Re: [Tutor] multiple assignment on one line

2009-11-22 Thread bob gailer
Shashwat Anand wrote: Ok, this is silly but i want to know is multiple assignment is possible in one line using "+=, -=, *= etc" operators on python 2.6.4 Read the manual: 6.3.1 Augmented assignment statements "target augop expression_list An augmented assignment evaluates the target (which, u

Re: [Tutor] multiple assignment on one line

2009-11-22 Thread Lie Ryan
Alan Gauld wrote: "Lie Ryan" wrote I was a bit surprised this doesn't work though: a, b += k, k What would you expect? I expect a, b += c, d to be a += c; b += d just like a, b = c, d to be a = c; b = d Remember that a,b = c,d is just tuple assignment without using parens (and pare

Re: [Tutor] multiple assignment on one line

2009-11-22 Thread Shashwat Anand
Ohh, I never thought it this way. Thanks for enlightening. On Sun, Nov 22, 2009 at 9:52 PM, Alan Gauld wrote: > > "Lie Ryan" wrote > > > I was a bit surprised this doesn't work though: > >> >> a, b += k, k >> >> > What would you expect? > Remember that > > a,b = c,d > > is just tuple assignment

Re: [Tutor] multiple assignment on one line

2009-11-22 Thread Alan Gauld
"Lie Ryan" wrote I was a bit surprised this doesn't work though: a, b += k, k What would you expect? Remember that a,b = c,d is just tuple assignment without using parens (and parens are not part of the tuple definition) So using tuples a,b += k,k would unwrap as a,b = (a,b) + (k,k

Re: [Tutor] multiple assignment on one line

2009-11-22 Thread Luke Paireepinart
On Sun, Nov 22, 2009 at 2:30 AM, Shashwat Anand wrote: > Ok, this is silly but i want to know is multiple assignment is possible in > one line using "+=, -=, *= etc" operators on python 2.6.4 > > like a,b = 0,1 which is equal to > a = 0 > b = 1 > on seperate lines. > similarly a = b = 0 which is e

Re: [Tutor] multiple assignment on one line

2009-11-22 Thread Lie Ryan
Alan Gauld wrote: "Shashwat Anand" wrote Can we pack these two statements in one line ? a += k b += k of course a,b +=k will not work but is there any such option available? Not that I'm aware. And when I tried it just to see what happens it killed IDLE completely - Window disappeared

Re: [Tutor] multiple assignment on one line

2009-11-22 Thread Lie Ryan
Shashwat Anand wrote: Ok, this is silly but i want to know is multiple assignment is possible in one line using "+=, -=, *= etc" operators on python 2.6.4 like a,b = 0,1 which is equal to a = 0 b = 1 on seperate lines. similarly a = b = 0 which is equal to a = 0 b = 0 on seperate lines. Can we

Re: [Tutor] multiple assignment on one line

2009-11-22 Thread Shashwat Anand
thanks Alan, i was just curious, thats it. And yeah, simplest is best :) On Sun, Nov 22, 2009 at 2:38 PM, Alan Gauld wrote: > > "Shashwat Anand" wrote > > > Can we pack these two statements in one line ? >> a += k >> b += k >> > > of course a,b +=k will not work but is there any such option av

Re: [Tutor] multiple assignment on one line

2009-11-22 Thread Alan Gauld
"Shashwat Anand" wrote Can we pack these two statements in one line ? a += k b += k of course a,b +=k will not work but is there any such option available? Not that I'm aware. And when I tried it just to see what happens it killed IDLE completely - Window disappeared and everything! Y

[Tutor] multiple assignment on one line

2009-11-22 Thread Shashwat Anand
Ok, this is silly but i want to know is multiple assignment is possible in one line using "+=, -=, *= etc" operators on python 2.6.4 like a,b = 0,1 which is equal to a = 0 b = 1 on seperate lines. similarly a = b = 0 which is equal to a = 0 b = 0 on seperate lines. Can we pack these two statement

Re: [Tutor] Multiple Assignment from list.

2005-12-28 Thread Paul Kraus
Never mind. i figured this out. the top line of a file i was reading in and splitting only had 1 char so "fields" on that line was not a list. I fixed this. On Wednesday 28 December 2005 3:12 pm, Paul Kraus wrote: > How do I code this in python. Assuming fields is a list of 3 things. > > (myfield

[Tutor] Multiple Assignment from list.

2005-12-28 Thread Paul Kraus
How do I code this in python. Assuming fields is a list of 3 things. (myfielda, myfieldb, myfieldc) = fields When i try that I get ValueError: need more than 1 value to unpack. If i print fields it is in need printed as ['somestring','somestring','somestring'] TIA, -- Paul Kraus =-=-=-=-=-=-=-

Re: [Tutor] multiple assignment

2005-10-18 Thread Kent Johnson
Vincent Gulinao wrote: > Haha. Cool. > > I think it's better than... > > if str.find(" "): > str1, str2, str3 = str.split(" ", 3) > else: > str1, str2, str3, rest = str, None, None, None Less buggy, too - your version will fail if str="1 2" or "1 2 3 4" BTW don't use str as the name of

Re: [Tutor] multiple assignment

2005-10-18 Thread Kent Johnson
Vincent Gulinao wrote: > I was fascinated when I learned that I can do this in Python: > > (str1, str2, str3, rest) = str.split(" ", 3) > > Later that I realize that str could contain values of less than 4 > strings, in which case it would complain something like -- ValueError: > unpack list of

Re: [Tutor] multiple assignment

2005-10-17 Thread John Fouhy
On 18/10/05, Vincent Gulinao <[EMAIL PROTECTED]> wrote: > I was fascinated when I learned that I can do this in Python: > > (str1, str2, str3, rest) = str.split(" ", 3) > [...] > In essence, I'd like to capture the first 3 words in a string. If str is > less than 3 words then any or all of the co

[Tutor] multiple assignment

2005-10-17 Thread Vincent Gulinao
I was fascinated when I learned that I can do this in Python: (str1, str2, str3, rest) = str.split(" ", 3) Later that I realize that str could contain values of less than 4 strings, in which case it would complain something like -- ValueError: unpack list of wrong size. Now I don't want to