On Fri, Aug 11, 2006, Greg Ewing wrote: > Phillip J. Eby wrote: >> >> I think it's a warning sign because I *know* what augmented >> assignment's semantics are supposed to be and I *still* try to use it >> with setdefault() sometimes -- but only when I'm doing an augmented >> assignment. I never mistakenly try to assign to a function call in >> any other circumstance. > > I think this problem arises because of the dual semantics of augmented > assignment. One tends to have two *different* mental models of what it > does, depending on whether the object in question is immutable: > > (1) For immutable objects: > > x += y <--> x = x + y > > (2) For mutable objects: > > x += y <--> x.__iadd__(y) What I try to do is always remember that x += y <--> x = x.__iadd__(y) which mostly solves the problem. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4