Assign variables wherever, whenever you want.
Project description
let3
Assign variables wherever, whenever you want.
Overview
let3 is a strict fork of Taylor Marks’s let package with a fix allowing to work with Python3 or higher and with a little code reformatting and minor improvements.
Overview below is a copy from the original let website (with only the necessary changes regarding let3).
Quick Start
Once you’ve installed, you can really quickly verified that it works with just this:
>>> from let import let
>>> if let(count = len("Hello World!")):
... print(count)
12
Documentation
In C, Java, and many other languages, it’s possible to assign variables inside of if or while condition statements. This is useful in allowing you to concisely both assign the value, and check whether a condition is met.
This ability doesn’t exist in Python, because of the thought that when people write something like:
if row = db.fetch_results():
...
They may have actually meant:
if row == db.fetch_results():
...
Personally, I have never made this mistake. It seems far more like a theoretical mistake that could plausibly happen than one that actually happens and warrants removing features, as was chosen in Python.
Anyways, the let function in this module gives you something very close to that ability in other languages. A few examples:
if let(name = longInstanceName.longAttributeName):
...
# Yes, db.fetch_results() should just return a generator. No, it doesn't.
while let(results = db.fetch_results()):
...
if let(count = len(nameValuePair)) != 1:
raise Exception(f"Bad amount: {count}")
Installation
Prerequisites:
Python 3.10 or higher
pip
To install run:
python -m pip install --upgrade let3
Development
Prerequisites:
Development is strictly based on nox. To install it run:
python -m pip install --upgrade nox
Visit Development page.
Installation from sources:
clone the sources:
git clone https://github.com/karpierz/let3 let3
and run:
python -m pip install ./let3
or on development mode:
python -m pip install --editable ./let3
License
Copyright (c) 2016-2026 Adam KarpierzCopyright (c) 2016 Taylor MarksLicensed under the MIT LicensePlease refer to the accompanying LICENSE file.
Sponsoring
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file let3-2.2.0.tar.gz.
File metadata
- Download URL: let3-2.2.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65b54205fceddca7694f0ff38508b40452f50e932e2208914112b985a867a990
|
|
| MD5 |
ef85a6506a84cd1d0827fd3f59687092
|
|
| BLAKE2b-256 |
a5e141321caa531624b5dc5f6b6765f9d8b2ba572618bb5632a02a6cef532a05
|
File details
Details for the file let3-2.2.0-py3-none-any.whl.
File metadata
- Download URL: let3-2.2.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aeaf9a6ddeb1ce50708be75927a81c4511e9da2e1192550664efe2bc3dfbfdb8
|
|
| MD5 |
304724bb28eb28ea7ae317d815360fb6
|
|
| BLAKE2b-256 |
858fb37d22caa9365576b7b9ebffbc8fd48703c810ce7ea256af891d90da407c
|