Python scope is too complicated
Ivan Van Laningham
ivanlan at pauahtun.org
Sun Mar 20 17:01:19 EST 2005
Hi All--
Dan Bishop wrote:
>
> > """In Python, there are only two scopes. The global and the local.
> > The global scope is a dictionary while the local, in the case of a
> > function is extremely fast. There are no other scopes.
>
> This isn't true anymore, now that generator comprehensions have been
> added to the language.
>
> >>> x = 17
> >>> sum(x for x in xrange(101))
> 5050
> >>> x
> 17
>
The equivalent in list comprehensions which currently allows the x to
leak out into its containing scope is going away soon. Will that be
another scope? Or are generator and list comprehensions only one scope?
Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
More information about the Python-list
mailing list