[Python-ideas] Assignments in list/generator expressions

Terry Reedy tjreedy at udel.edu
Tue Apr 12 18:35:40 CEST 2011


On 4/12/2011 4:31 AM, Nick Coghlan wrote:

> 1. You wish to avoid polluting the current namespace with working
> variables and helper functions (most relevant for module and class
> level code, but may also be relevant for functions in some closure
> related contexts)

I am puzzled why namespace sanitation fans are so allergic to the 
namespace cleanup statement == 'del'.

> 2. You wish to provide greater prominence to the final statement in a
> series of operations, making it clear to the reader that the other
> statements are mere setup for that final step.

Final position *is* a place of prominence.

> This is similar to the
> principle of decorators, where the important information is the
> function name, parameters, annotations and applied decorators, while
> the precise implementation details will be uninteresting for many
> readers.

And decorators put the def line *last* instead of first, whereas the 
proposed 'given' moves the punchline statement from last to first.

A module or class doc string can list the important names, which should 
be readable and multiple chars. A module can reiterate with __all__. 
Private names get a leading _. Temporary names can be short and deleted 
when not needed.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list