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.11 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
Release files for let3 2.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| let3-2.4.4.tar.gz | 15.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| let3-2.4.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.7 kB
Release files / let3-2.4.4.tar.gz
| Download URL | let3-2.4.4.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4dae48d11b29e589f1e259e72aa0660f937d43b09f8e50c8f1f993a0966005f1
|
|
BLAKE2b-256 checksum How to use checksums |
fb5b8f6bacf005f0f0cb449c3b3f061af2320852fbacededb463b66d1d4c0e1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / let3-2.4.4-py3-none-any.whl
| Download URL | let3-2.4.4-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38cab87b1da86582855e08a0c918c0b0bbeeecc193f398d577651d044d182686
|
|
BLAKE2b-256 checksum How to use checksums |
b5cdcf521cb6ee38bcb6c1a8f4f95e1e521a98dfcac2ccd3e9cc79595720c3a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|