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.

Overview below is a copy from the original let website (with only the necessary changes regarding let3).

Installation

Install via pip:

$ python -m pip install --upgrade let3

Done.

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('Bad amount: {}'.format(count))

Installation prerequisites

Development

Visit development page

Installation from sources:

Clone the sources and run:

python -m pip install ./let3

or on development mode:

python -m pip install --editable ./let3

Prerequisites:

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

    python -m pip install tox

License

Copyright (c) 2016 Taylor Marks
Copyright (c) 2016-2018 Adam Karpierz

Licensed under the MIT License
Please refer to the accompanying LICENSE file.

Authors

Changelog

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.0.9.zip (13.2 kB view details)

Uploaded Source

File details

Details for the file let3-1.0.9.zip.

File metadata

  • Download URL: let3-1.0.9.zip
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for let3-1.0.9.zip
Algorithm Hash digest
SHA256 44688be98a6b61de14815af0da9414c9adbecd426e01f2b5fbe68abecb0c174a
MD5 a97b0cf4d19b1085cde128fa04594619
BLAKE2b-256 f4f77ca923b8ba2c3d9c5d0d3bf38ccff508bb6c1d4e2ee4a89d14a56c06f8d0

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