Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Assign variables wherever, whenever you want.

Project Description

Assign variables wherever, whenever you want.

Installation

Install via pip:

$ pip install let

Done.

If you insist on the (slightly) harder way of installing, from source, you know how to do it already and don’t need my help.

I might later upload the source to: https://github.com/TaylorSMarks/let

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))
Release History

Release History

This version
History Node

1.0.1

History Node

1.0.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
let-1.0.1.tar.gz (3.8 kB) Copy SHA256 Checksum SHA256 Source Feb 26, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting