block scope?

Alexander Schmolck a.schmolck at gmail.com
Sun Apr 8 05:54:08 EDT 2007


Neal Becker <ndbecker2 at gmail.com> writes:

> One thing I sometimes miss, which is common in some other languages (c++),
> is idea of block scope.  It would be useful to have variables that did not
> outlive their block, primarily to avoid name clashes.  This also leads to
> more readable code.  

I have on occassion used lambda as a poor-man's let, but only if I needed to
avoid multiple evaluation:

 res = (lambda x=blah(...), y=blahz(...):  f(x*y,x+y))()

I'm sure most people would debate it's more readable, but it's IMO superior to
cleaning up manually with ``del``. I sometimes also find it useful to avoid
cluttering up the interactive shell.

'as



More information about the Python-list mailing list