loop scope
Jacek Generowicz
jacek.generowicz at cern.ch
Fri Mar 19 03:35:56 EST 2004
danb_83 at yahoo.com (Dan Bishop) writes:
> One way to avoid this problem is to have an explicit scope-creating
> construct instead.
>
> def foo(a):
> scope outer:
> a = 3
> scope inner:
> a = 4
> print a # prints 4
> print outer.a # prints 3
> print foo.a # prints the function parameter
> print a # inner.a is out of scope, so prints 3
> foo.b = 5 # Creates a new function-scope variable.
> print b # prints 5
I think that the elegance of nested scopes relies on the language
being able to find the innermost scope which contains the given name,
_without_ help from the programmer.
But this relies on being able to distinguish binding from re-binding.
More information about the Python-list
mailing list