Class Variable Access and Assignment
Antoon Pardon
apardon at forel.vub.ac.be
Fri Nov 4 03:23:05 EST 2005
Op 2005-11-03, Magnus Lycka schreef <lycka at carmen.se>:
> Antoon Pardon wrote:
>> There is no instance variable at that point. How can it add 2, to
>> something that doesn't exist at the moment.
>
> Because 'a += 1' is only a shorthand for 'a = a + 1' if a is an
> immutable object? Anyway, the behaviour is well documented.
>
> http://docs.python.org/ref/augassign.html says:
>
> An augmented assignment expression like x += 1 can be rewritten as x = x
> + 1 to achieve a similar, but not exactly equal effect. In the augmented
> version, x is only evaluated once.
Then couldn't we expect that the namespace resolution is also done
only once?
I say that if the introduction on += like operators implied that the
same mentioning of a name would in some circumstances be resolved to
two different namespaces, then such an introduction would better have
not occured.
Would it be too much to ask that in a line like.
x = x + 1.
both x's would resolve to the same namespace?
--
Antoon Pardon
More information about the Python-list
mailing list