One last shot at the Augmented Assignment PEP
Alex Martelli
aleaxit at yahoo.com
Fri Sep 15 08:22:15 EDT 2000
More information about the Python-list mailing list
Fri Sep 15 08:22:15 EDT 2000
- Previous message (by thread): One last shot at the Augmented Assignment PEP
- Next message (by thread): One last shot at the Augmented Assignment PEP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Fredrik Lundh" <effbot at telia.com> wrote in message news:TQbw5.367$n4.28461 at newsc.telia.net... > warren wrote: > > I've always been tempted to tell people to think of "=" as binding, not > > assignment, but even in versions <= 2.0, it didn't always mean that: > > > > a = [0] > > a[0] = 1 > > > > No symbol rebinding here, although we have copied a reference. > > well, it's only binding if the assignment target is > a simple name. For me, at least, my mental model of what's going on works better if I say that it's binding anyway -- i.e., that you're still binding (or re-binding) a *slot*, whether that slot is "simple-name"'d or not. > all other assignments are just nice ways to write > certain method calls: > > a[0] = 1 > a.__setitem__(0, 1) > > a.x = 1 > a.__setattr__("x", 1) And (although this is not guaranteed to work in the future...): a = 1 globals().__setitem__('a', 1) No major difference. "Simple-names" are clearly more subject to present or future optimization (and thus, a little magic behind the covers) -- so locals() is readonly (and writing to it may not really DO anything...), and globals() may one day be somewhat optimized too, etc. But I do not see these (quite worthwhile) optimization-possibilities as breaking the chance to reason about a mental model of runtime execution in terms of slot being bound/unbound/re-bound to objects, and names just being one (handy) way to navigate to certain of these slots. Alex
- Previous message (by thread): One last shot at the Augmented Assignment PEP
- Next message (by thread): One last shot at the Augmented Assignment PEP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list