danb_83 at yahoo.com
Fri Mar 19 21:52:08 CET 2004
Josiah Carlson <jcarlson at nospam.uci.edu> wrote in message news:<c3d4r8$gho$2 at news.service.uci.edu>...
> > 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
> Ick. Thank god Python doesn't seem to be heading in this direction.
I agree. Just because this was my idea doesn't mean I have to like it ;-)
I'm satified with the scope rules the way they are, except for list comprehensions.
More information about the Python-list