question about list extension

2010-04-16 Thread J
Ok... I know pretty much how .extend works on a list... basically it just tacks the second list to the first list... like so: lista=[1] listb=[2,3] lista.extend(listb) print lista; [1, 2, 3] what I'm confused on is why this returns None: lista=[1] listb=[2,3] print lista.extend(listb)

Re: question about list extension

2010-04-16 Thread Bruno Desthuilliers
J a écrit : Ok... I know pretty much how .extend works on a list... basically it just tacks the second list to the first list... like so: lista=[1] listb=[2,3] lista.extend(listb) print lista; [1, 2, 3] what I'm confused on is why this returns None: So why the None? Is this because what's

Re: question about list extension

2010-04-16 Thread Lie Ryan
On 04/16/10 23:41, J wrote: Ok... I know pretty much how .extend works on a list... basically it just tacks the second list to the first list... like so: lista=[1] listb=[2,3] lista.extend(listb) print lista; [1, 2, 3] what I'm confused on is why this returns None: lista=[1]

Re: question about list extension

2010-04-16 Thread J. Cliff Dyer
On Sat, 2010-04-17 at 00:37 +1000, Lie Ryan wrote: On 04/16/10 23:41, J wrote: So, what I'm curious about, is there a list comprehension or other means to reduce that to a single line? from itertools import chain def printout(*info): print '\n'.join(map(str, chain(*info))) or

Re: question about list extension

2010-04-16 Thread Terry Reedy
On 4/16/2010 9:41 AM, J wrote: Ok... I know pretty much how .extend works on a list... basically it just tacks the second list to the first list... like so: lista=[1] listb=[2,3] lista.extend(listb) print lista; [1, 2, 3] This shows right here that lista is extended in place. If you are not

Re: question about list extension

2010-04-16 Thread J
On Fri, Apr 16, 2010 at 15:16, Terry Reedy tjre...@udel.edu wrote: On 4/16/2010 9:41 AM, J wrote: Ok... I know pretty much how .extend works on a list... basically it just tacks the second list to the first list... like so: lista=[1] listb=[2,3] lista.extend(listb) print lista; [1, 2,

Re: list extension ?

2008-06-30 Thread Bruno Desthuilliers
Stef Mientki a écrit : hello, I basically need a list with a few extra attributes, so I derived a new object from a list, and it works perfect. But I wonder why the newly derived list component is much more flexible ? # so here is the new list object class tGrid_List ( list ) : pep08: class

Re: list extension ?

2008-06-30 Thread Stef Mientki
thanks guys, def __init__ ( self, value = [] ) : Gotcha : default argument values are eval'd only once. Also, it would make more sense IMHO to follow the parent's class initializer's behaviour: def __init__(self, *args) list.__init__ ( self, value )

Re: list extension ?

2008-06-30 Thread Stef Mientki
thanks guys, def __init__ ( self, value = [] ) : Gotcha : default argument values are eval'd only once. Also, it would make more sense IMHO to follow the parent's class initializer's behaviour: def __init__(self, *args) list.__init__ ( self, value )

Re: list extension ?

2008-06-30 Thread [EMAIL PROTECTED]
On 30 juin, 21:05, Stef Mientki [EMAIL PROTECTED] wrote: thanks guys, def __init__ ( self, value = [] ) : Gotcha : default argument values are eval'd only once. Also, it would make more sense IMHO to follow the parent's class initializer's behaviour: Ah hem Sorry, should have

list extension ?

2008-06-29 Thread Stef Mientki
hello, I basically need a list with a few extra attributes, so I derived a new object from a list, and it works perfect. But I wonder why the newly derived list component is much more flexible ? # so here is the new list object class tGrid_List ( list ) : def __init__ ( self, value = [] ) :

Re: list extension ?

2008-06-29 Thread Scott David Daniels
Stef Mientki wrote: ... (approximately, I PEP-8'ed it a bit) ... class tGrid_List(list): def __init__(self, value=[]): list.__init__(self, value) # and with this new list component, I can add new attributes on the fly a = tGrid_list([2, 3]) a.New_Attribute = 'some text' # I'm not