block scope?

Chris Mellon arkanes at gmail.com
Fri Apr 6 12:41:24 EDT 2007


On 4/6/07, Neal Becker <ndbecker2 at gmail.com> wrote:
> 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 wonder if this has been discussed?
>

Block scope as a way to prevent name clashes is usually solved by
refactoring (in C++, too) - if you can't disambiguate locals in a
function it's usually a sign that your function does to much and needs
to be broken up.

Block scope as a way to control object lifetimes (automatic variables,
or RAII) is addressed (in 2.5) by context managers or (pre-2.5)
try/finally blocks.



More information about the Python-list mailing list