Closures in python
Alex Martelli
aleax at aleax.it
Sun Sep 21 17:18:20 EDT 2003
nospam wrote:
> JCM wrote:
>> >>> def foo():
>> ... x = [3]
>> ... def bar():
>> ... x[0] += 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.
Alex
More information about the Python-list
mailing list