Skip to main content

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.

PyPI record.

Documentation.

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:

To install run:

python -m pip install --upgrade let3

Development

Prerequisites:

  • Development is strictly based on tox. To install it run:

    python -m pip install --upgrade tox

Visit Development page.

Installation from sources:

clone the sources:

git clone https://github.com/karpierz/let3.git let3

and run:

python -m pip install ./let3

or on development mode:

python -m pip install --editable ./let3

License

Copyright (c) 2016-2024 Adam Karpierz
Copyright (c) 2016 Taylor Marks
Licensed under the MIT License
Please refer to the accompanying LICENSE file.

Authors

Changelog

1.1.0 (2024-09-30)

  • Drop support for Python 3.8

  • Setup (dependencies) update.

1.0.25 (2024-08-13)

  • Add support for Python 3.13

  • Setup (dependencies) update.

1.0.24 (2024-01-30)

  • Setup update (now based on tox >= 4.0).

  • Add support for Python 3.12

  • Drop support for Python 3.7

  • Add support for PyPy 3.9 and 3.10

  • Add support for PyPy 3.7 and 3.8

  • Copyright year update.

  • Tox configuration has been moved to pyproject.toml

  • Cleanup.

1.0.21 (2022-10-18)

  • Tox configuration has been moved to pyproject.toml

1.0.20 (2022-08-22)

  • Add support for Python 3.10 and 3.11

  • Setup update (currently based mainly on pyproject.toml).

1.0.19 (2022-01-10)

  • Drop support for Python 3.6.

  • Copyright year update.

  • Setup update.

1.0.17 (2021-10-14)

  • Setup update.

1.0.16 (2021-07-19)

  • Bugfix: ‘let’ works now also on highest (e.g. module) level.

  • Setup general update and improvement.

1.0.15 (2020-10-17)

  • Add support for Python 3.8 and 3.9.

  • Drop support for Python 3.5.

  • Drop support for Python 2.

  • Setup: fix an improper dependencies versions.

  • Setup general update and cleanup.

  • Fixed docs setup.

  • Cleanup.

1.0.10 (2019-05-21)

  • Update required setuptools version.

  • Setup update and improvements.

  • This is the latest release that supports Python 2.

1.0.9 (2018-11-08)

  • Drop support for Python 2.6 and 3.0-3.3

  • Update required setuptools version.

1.0.8 (2018-05-08)

  • Update required setuptools version.

  • Improve and simplify setup and packaging.

1.0.7 (2018-02-26)

  • Improve and simplify setup and packaging.

1.0.6 (2018-01-28)

  • Fix a bug and inconsistencies in tox.ini

  • Update of README.rst.

1.0.3 (2018-01-24)

  • Update required Sphinx version.

  • Update doc Sphinx configuration files.

1.0.2 (2017-11-18)

  • Setup improvements.

  • Other minor improvements.

1.0.1 (2017-01-05)

  • Creating a fork of Taylor Marks’s let package with a fix allowing to work with Python3 or higher.

  • Minor improvements.

Changes of the original let:

1.0.1 (Feb 25, 2016)

  • Let now assigns the variables to the global namespace always - never the local namespace. The Python interpreter sometimes optimizes variables within the local namespace - it’s best not to change values behind its back, as it leads to very difficult to discover bugs.

1.0.0 (Feb. 7, 2016)

  • Initial commit

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

let3-1.1.0.zip (20.5 kB view details)

Uploaded Source

Built Distribution

let3-1.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file let3-1.1.0.zip.

File metadata

  • Download URL: let3-1.1.0.zip
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for let3-1.1.0.zip
Algorithm Hash digest
SHA256 f29f64342d0b8973b1465ad6cf743e107904a5685d0a7e3e623b18144a329151
MD5 30ca8e5b4710c4ea126b8d6316b7d47f
BLAKE2b-256 f3951946668c7766b9aeda7de0b9da1ec3a6d0e8ee25a1e66a55f52dc059a5be

See more details on using hashes here.

File details

Details for the file let3-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: let3-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for let3-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15503a5f1bedd9d128eb6e21d5b993071c68ce553f0c9e497bf79d5285fe0ca3
MD5 011e16e8e3881e6b2e42bef48a136516
BLAKE2b-256 12c183a43ce4b6039ed4347b6781bd93e3e3217f20f03a09e9e5fda30ca22427

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page