Augmented assignment (was Re: Something in the function tutorial confused me.)

2007-08-11 Thread Aahz
In article [EMAIL PROTECTED], Neil Cerutti [EMAIL PROTECTED] wrote: On 2007-08-11, Alex Martelli [EMAIL PROTECTED] wrote: Neil Cerutti [EMAIL PROTECTED] wrote: ... The Python Language Reference seems a little confused about the terminology. 3.4.7 Emulating numeric types 6.3.1

Re: Augmented assignment (was Re: Something in the function tutorial confused me.)

2007-08-11 Thread Roel Schroeven
Aahz schreef: In article [EMAIL PROTECTED], Neil Cerutti [EMAIL PROTECTED] wrote: On 2007-08-11, Alex Martelli [EMAIL PROTECTED] wrote: Neil Cerutti [EMAIL PROTECTED] wrote: ... The Python Language Reference seems a little confused about the terminology. 3.4.7 Emulating numeric

Re: Augmented assignment (was Re: Something in the function tutorial confused me.)

2007-08-11 Thread Aahz
In article [EMAIL PROTECTED], Roel Schroeven [EMAIL PROTECTED] wrote: Aahz schreef: Although Alex is essentially correct, the situation is a bit more complex and you are correct that augmented assignment allows the object to decide whether to mutate in place. However, the critical part of

Re: Augmented assignment (was Re: Something in the function tutorial confused me.)

2007-08-11 Thread Roel Schroeven
Aahz schreef: def foo(bar): bar[0] += ['zap'] ... import dis dis.dis(foo) 1 0 LOAD_FAST0 (bar) 3 LOAD_CONST 1 (0) 6 DUP_TOPX 2 9 BINARY_SUBSCR 10 LOAD_CONST

Re: Augmented assignment (was Re: Something in the function tutorial confused me.)

2007-08-11 Thread OKB (not okblacke)
Aahz wrote: tup=([],) tup[0] += ['zap'] Traceback (most recent call last): File stdin, line 1, in module TypeError: 'tuple' object does not support item assignment snip Obviously, you can easily work around it: t = ([],) l = t[0] l += ['foo'] t (['foo'],) This is quite

Re: Augmented assignment (was Re: Something in the function tutorial confused me.)

2007-08-11 Thread Roel Schroeven
OKB (not okblacke) schreef: Aahz wrote: tup=([],) tup[0] += ['zap'] Traceback (most recent call last): File stdin, line 1, in module TypeError: 'tuple' object does not support item assignment snip Obviously, you can easily work around it: t = ([],) l = t[0] l += ['foo'] t

Re: Augmented assignment (was Re: Something in the function tutorial confused me.)

2007-08-11 Thread Aahz
In article [EMAIL PROTECTED], OKB (not okblacke) [EMAIL PROTECTED] wrote: This sentence is phrased as though it is the whole story, but it isn't, because the operation might not in fact wind up being an assignment. Shouldn't there be an except see below or something there, to alert the

Re: Augmented assignment (was Re: Something in the function tutorial confused me.)

2007-08-11 Thread Aahz
In article [EMAIL PROTECTED], Roel Schroeven [EMAIL PROTECTED] wrote: I used to interpret the target in 'The target is only evaluated once' more like an L-value in C/C++. That's not correct, of course, but I didn't understand exactly how wrong it was until now. It's true almost everywhere