Greg Wilson wrote: 3. "Where is '+=' ?" and "Why can't I redefine assignment?"
Ka-Ping Yee: += would be nice; not a really big deal to me.
Redefining assignment would get way too confusing, i think. __setitem__ has always been good enough for me.
It'll make a big difference to NumPy (avoiding temporaries, etc.). Also hard to explain why you can redefine assignment to an array element, but not to a scalar variable.
FWIW, I never got that question by my students. I did get that question in a consulting context, but it was a very advanced problem having to do with needing control over references to huge external objects, etc. After much trial and error I've come up with a 'method' for describing assignment, references, names, etc., which I've found works well in practice. I demonstrate the concept of names & references on a whiteboard with trivial cases like a = 1 + 3 and then I move on to b = 3 c = 5 a = b + c and then a = [b,c] and then I graduate to the a = [0]*3 and then finally a = [[0]*3]*3 and when they get that I know I've succeeded in getting the concept of assignment in Python across. It's much too hard to describe in email because it requires a blackboard and drawing arrows, erasing arrows, etc., but someday I can demonstrate (SD2000?). Anyway, it's possible that your students are just too smart for their own good, Greg. =) --david