Re: a trick with lists ?

2008-02-08 Thread Matthew_WARREN
> On Feb 7, 12:20 pm, "Sébastien Vincent" free.fr> > wrote: > > I've found some class on the Net which takes basically this form : > > > > ## > > class Foo: > > def __init__(self): > > self.tasks = [] > >... > > > > def method1(self): > > tasks = [] > > w

Re: a trick with lists ?

2008-02-08 Thread "S�bastien Vincent"
Thank you, that's very clear indeed. "Helmut Jarausch" <[EMAIL PROTECTED]> a écrit dans le message de news: [EMAIL PROTECTED] > Sébastien Vincent > I've found some class on the Net which takes basically this form : >> >> ## >> class Foo: >> def __init__(self): >> self.tasks = []

Re: a trick with lists ?

2008-02-08 Thread Helmut Jarausch
Sébastien Vincent I've found some class on the Net which takes basically this form : > > ## > class Foo: > def __init__(self): > self.tasks = [] >... > > def method1(self): > tasks = [] > while True: > ... > append/pop elements into/from tasks > ...

Re: a trick with lists ?

2008-02-07 Thread Steve Holden
Tim Chase wrote: self.tasks[:] = tasks What I do not fully understand is the line "self.tasks[:] = tasks". Why does the guy who coded this did not write it as "self.tasks = tasks"? What is the use of the "[:]" trick ? >>> It changes the list in-place. If i

Re: a trick with lists ?

2008-02-07 Thread Ed Leafe
On Feb 7, 2008, at 3:19 PM, James Turk wrote: > if you do > a = [1,2,3] > b = [] > b = a > > then assign: b[1] = 9 > now a[1] == 9 as well > > with a[:] = b you are actually getting a copy of the list rather than > an alias Of course, this only works if 'b' is already a list. A more comm

Re: a trick with lists ?

2008-02-07 Thread Tim Chase
>>> self.tasks[:] = tasks >>> >>> What I do not fully understand is the line "self.tasks[:] = tasks". Why >>> does >>> the guy who coded this did not write it as "self.tasks = tasks"? What is >>> the >>> use of the "[:]" trick ? >> >> It changes the list in-place. If it has been given to ot

Re: a trick with lists ?

2008-02-07 Thread [EMAIL PROTECTED]
On 7 fév, 22:16, Steve Holden <[EMAIL PROTECTED]> wrote: > Diez B. Roggisch wrote: > >> self.tasks[:] = tasks > > >> What I do not fully understand is the line "self.tasks[:] = tasks". Why > >> does > >> the guy who coded this did not write it as "self.tasks = tasks"? What is > >> the > >> u

Re: a trick with lists ?

2008-02-07 Thread imho
Steve Holden ha scritto: >>> What I do not fully understand is the line "self.tasks[:] = tasks". >>> Why does the guy who coded this did not write it as "self.tasks = >>> tasks"? What is the use of the "[:]" trick ? >> >> It changes the list in-place. If it has been given to other objects, >> i

Re: a trick with lists ?

2008-02-07 Thread James Turk
On Feb 7, 12:20 pm, "Sébastien Vincent" free.fr> wrote: > I've found some class on the Net which takes basically this form : > > ## > class Foo: > def __init__(self): > self.tasks = [] >... > > def method1(self): > tasks = [] > while True: > ... > append

Re: a trick with lists ?

2008-02-07 Thread Steve Holden
Diez B. Roggisch wrote: > "S����������������������������������������������" schrieb: >> I've found some class on the Net which takes basically this form : >> >> ## >> class Foo: >> def __init__(self)

Re: a trick with lists ?

2008-02-07 Thread Diez B. Roggisch
"S����������������������������������������������" schrieb: > I've found some class on the Net which takes basically this form : > > ## > class Foo: > def __init__(self): > self.tasks = [] >

a trick with lists ?

2008-02-07 Thread "S�bastien Vincent"
I've found some class on the Net which takes basically this form : ## class Foo: def __init__(self): self.tasks = [] ... def method1(self): tasks = [] while True: ... append/pop elements into/from tasks ... if condition : break self.tasks[:] = t