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 everywh

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

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 "", line 1, in TypeError: 'tuple' object does not support item assignment > >> Obviously, you can easily work around it: >> > t = ([],) > l = t

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 "", line 1, in >>> TypeError: 'tuple' object does not support item assignment > Obviously, you can easily work around it: > t = ([],) l = t[0] l += ['foo'] t > (['foo'],)

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_

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 critic

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. >>

Re: Augmented assignment

2006-02-21 Thread gene tani
Terry Hancock wrote: > On Tue, 21 Feb 2006 10:55:42 +0530 > Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: > Seriously, > I think they are usually equivalent internally, > at least for immutable objects. > yah, but when you do augmented assigns on lists, or mix immutable an dmutable: http://zeph

Re: Augmented assignment

2006-02-21 Thread Terry Hancock
On Tue, 21 Feb 2006 10:55:42 +0530 Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: > Is there any gain in performance because of > augmented assignments. > > x += 1 vs x = x+1 Yep. I perform better when I only type names once. Especially if they are long: length_of_object_I_must

Re: Augmented assignment

2006-02-21 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Terry Reedy wrote: >> Program performance might be noticeable if 'x' is something like a.b.c.d >> that takes some lookup time. But again, I would use the += form for >> readability without testing run time. > > Would x=x + 1 be more

Re: Augmented assignment

2006-02-20 Thread Andrea Griffini
I think it heavily depends on what is "x". If x is bound to a mutable x=x+1 and x+=1 can not only have different speed but indeed can do two very unrelate things (the former probably binding to a new object, the latter probably modifying the same object). For example consider what happens with list

Re: Augmented assignment

2006-02-20 Thread bonono
Terry Reedy wrote: > Program performance might be noticeable if 'x' is something like a.b.c.d > that takes some lookup time. But again, I would use the += form for > readability without testing run time. Would x=x + 1 be more readable, regardless of the background(whether being introduced to the

Re: Augmented assignment

2006-02-20 Thread Suresh Jeevanandam
Thanks Alex. I was not aware of mtimeit. regards, Suresh Alex Martelli wrote: > Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: > >> Hi, >> Is there any gain in performance because of augmented assignments. >> >> x += 1 vs x = x+1 >> >> Or are both of them the same. > > Just *MEASURE*

Re: Augmented assignment

2006-02-20 Thread Terry Reedy
"Suresh Jeevanandam" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > Is there any gain in performance because of augmented assignments. > > x += 1 vs x = x+1 > > Or are both of them the same. The main gain is in programmer performance for writing a long name such as number_

Re: Augmented assignment

2006-02-20 Thread Alex Martelli
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: > Hi, > Is there any gain in performance because of augmented assignments. > > x += 1 vs x = x+1 > > Or are both of them the same. Just *MEASURE*, man! helen:~/apy alex$ python -mtimeit -s'x=0.0' 'x=x+1' 100 loops, best of 3: 0.507