New syntax for blocks

r rt8396 at
Fri Nov 13 05:10:29 CET 2009

On Nov 12, 7:44 pm, Steven D'Aprano <st... at REMOVE-THIS-> wrote
> Oh, but those hundreds of thousands of man-hours lost to bugs caused by
> assignment-as-an-expression is nothing compared to the dozens of man-
> minutes saved by having one fewer line of code!

OK, what *if* the variable would only be valid in *that* block and
*that* block only! My first idea was to have the variable avaiable in
the local scope (if that is correct terminology?) so if the
conditional was in global space the value would be available in global
space, alright? You follow me? Now forget all that and observe the
following. ;-)

if value=range(10):
    #this block *would* execute and "value" would be a valid name
    #but only IN this block!!!
elif value=fetch(0):
    #this block would *never* execute

value.append(1) -> this throws a NameError

Is that different than how other languages handle "assignment-by-
expression"? Will that avoid the cataclysmic downward spiral you speak
of? I can't see any problems with it AND it can still be applied to
myself and Carl's use cases.

Anybody is welcome to comment...?

More information about the Python-list mailing list