Scope rule pecularities

Donn Cave donn at u.washington.edu
Thu May 6 15:05:25 EDT 2004


In article <slrnc9kkdo.5fa.apardon at trout.vub.ac.be>,
 Antoon Pardon <apardon at forel.vub.ac.be> wrote:
...
> Beside you missed the point. I don't need solutions, I know the
> work arounds to make it work. The point is that although a += b
> is supposed to be syntactic sugar for a.__iadd__(b), you need
> a global (and even that won't help if you have nested functions
> and the a is on an intermediate level) to make the first work
> but not for the second.

+= is a bit of a wart.  The only value in it is that you can
execute this read-and-modify sequence with a single access in
some cases where accesses matter because of side effects.
(Single access higher up in an expression - e.g., if we have
a[0][0] += 1, you skip an a[0].)  If that seems like a silly
reason to take on this abominable kludge, I'm probably not
explaining it well - wasn't my idea.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list