loop scope
Mel Wilson
mwilson at the-wire.com
Tue Mar 16 12:48:18 EST 2004
In article <tyf7jxm49ap.fsf at pcepsft001.cern.ch>,
Jacek Generowicz <jacek.generowicz at cern.ch> wrote:
>Imagine we have a "nested" keyword which is similar to "global", only
>it ensures that the name is found in the nearest enclosing scope. Now
>the above problem could be resolved by defining "inc" as follows.
>
> def make():
> x = 0
> ...
> def inc(n):
> nested x
> x = x+n
> ...
>
>Works just like global would have done, only it is aware of the
>other socpes between local and global.
>
>> "Greg Ewing (using news.cis.dfn.de)" <wmwd2zz02 at sneakemail.com> writes:
>>
>> > It wouldn't do to make the whole (non-comprehension)
>> > for-loop a new scope, because that would make any
>> > variables assigned within the loop body local as well.
>
>Not if you have a "nested" keyword at your disposal.
>
>What situations would this not cover ?
Far too few. After the `nested x` statement comes
`nested nested x` and `nested nested nested x`, with the
accumulating maintenance headaches. All so that programmers
can choose data names badly.
Almost like running into `continue 17` within a nest of
loops.
Regards. Mel.
More information about the Python-list
mailing list