Closures in python
aleax at aleax.it
Sun Sep 21 23:18:20 CEST 2003
> JCM wrote:
>> >>> def foo():
>> ... x = 
>> ... def bar():
>> ... x += 1
>> This is actually one of my biggest complaints about Python. I'd like
>> syntactic disambiguation between definition and assignment in order to
>> have control over which scope you're assigning into.
> Maybe Python could be changed to let 'foo.x' inside function foo mean
> the x variable in foo?
That would be backwards-incompatible, since foo.x already means
something -- the attribute x of object foo (yep, functions are objects
and can have attributes), which has no connection whatsoever with
the local variable x inside (some of the potentially many currently
active instances of) functions named foo.
More information about the Python-list