Nested scopes, and augmented assignment
Bruno Desthuilliers
onurb at xiludom.gro
Wed Jul 5 09:18:29 EDT 2006
Antoon Pardon wrote:
(snip)
> Well no matter what explanation you give to it, and I understand how it
> works,
I'm not sure of this.
> I keep finding it strange that something like
>
> k = [0]
> def f(i):
> k[0] += i
> f(2)
>
> works but the following doesn't
>
> k = 0
> def f(i):
> k += i
> f(2)
>
>
> Personnaly I see no reason why finding a name/identifier on the
> leftside of an assignment should depend on whether the name
> is the target or prefix for the target.
>
It's not about "finding a name/identifier", it's about the difference
between (re)binding a name and mutating an object.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list