Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Walter Prins
On 4 January 2011 01:16, Vern Ceder wrote: > I believe you need to pass the object both to super() and to the method > itself, as in: > > super(parent, self).__init__(self, *args, **kwords) > > See the example at > http://docs.python.org/library/functions.html?highlight=super#super > > HTH, > > V

Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Alex Hall
On 1/3/11, Walter Prins wrote: > Sorry, my last post was too hasty. You also had a problem calling super. > It should be like this: > > class parent(object): > def __init__(self, l=None): >if l is None: self.l=[] >else: self.l=l > > class child(parent): > def __init__(self, *args, **kwo

Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Walter Prins
Sorry, my last post was too hasty. You also had a problem calling super. It should be like this: class parent(object): def __init__(self, l=None): if l is None: self.l=[] else: self.l=l class child(parent): def __init__(self, *args, **kwords): super(child, self).__init__(*args, **kwor

Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Alex Hall
On 1/3/11, Wayne Werner wrote: > On Mon, Jan 3, 2011 at 6:47 PM, Alex Hall wrote: > >> Hi all, >> I have a solitaire game in which I use a "Pile" class. This class is >> meant to hold a bunch of cards, so I subclass it for the deck, the ace >> stacks, and the seven main stacks, defining rules and

Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Vern Ceder
On Mon, Jan 3, 2011 at 7:47 PM, Alex Hall wrote: > Hi all, > I have a solitaire game in which I use a "Pile" class. This class is > meant to hold a bunch of cards, so I subclass it for the deck, the ace > stacks, and the seven main stacks, defining rules and methods for each > but also relying on

Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Wayne Werner
On Mon, Jan 3, 2011 at 6:47 PM, Alex Hall wrote: > Hi all, > I have a solitaire game in which I use a "Pile" class. This class is > meant to hold a bunch of cards, so I subclass it for the deck, the ace > stacks, and the seven main stacks, defining rules and methods for each > but also relying on

Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Walter Prins
On 4 January 2011 00:47, Alex Hall wrote: > class parent(object): > def __init__(self, l=None): > if l is None: l=[] > Missing "self". Perhaps you meant: class parent(object): def __init__(self, l=None): if l is None: self.l=[] else: self.l=l Walter __

Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Alan Gauld
"Alex Hall" wrote class parent(object): def __init__(self, l=None): if l is None: l=[] l is a local variable inside init(). You wanted self.l... HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor ma

[Tutor] subclass not inheriting attributes?

2011-01-03 Thread Alex Hall
Hi all, I have a solitaire game in which I use a "Pile" class. This class is meant to hold a bunch of cards, so I subclass it for the deck, the ace stacks, and the seven main stacks, defining rules and methods for each but also relying on the parent Pile class's methods and attributes. However, I k

Re: [Tutor] subclass question

2009-12-21 Thread bob gailer
David Perlman wrote: If I make a subclass of a built-in class, like this: class mylist(list): def __init__(self): list.__init__(self) Then it is valid for me to do this: >>> x=mylist() >>> x.hello=3 >>> But I can't do this: >>> y=list() >>> y.hello=3 Traceback (most recent call l

Re: [Tutor] subclass question

2009-12-20 Thread Rich Lovely
2009/12/20 David Perlman : > If I make a subclass of a built-in class, like this: > > class mylist(list): >    def __init__(self): >        list.__init__(self) > > Then it is valid for me to do this: > x=mylist() x.hello=3 > > But I can't do this: > y=list() y.hello=3 > Tra

[Tutor] subclass question

2009-12-19 Thread David Perlman
If I make a subclass of a built-in class, like this: class mylist(list): def __init__(self): list.__init__(self) Then it is valid for me to do this: >>> x=mylist() >>> x.hello=3 >>> But I can't do this: >>> y=list() >>> y.hello=3 Traceback (most recent call last): File "", line

Re: [Tutor] subclass

2006-02-03 Thread Kent Johnson
Christopher Spears wrote: > Here is a problem I'm working on out of Learning > Python: > > Make a subclass of MyList from exercise 2 called > MyListSub which extends MyList to print a message to > stdout before each overloaded operation is called and > counts the number of calls. MyListSub should

[Tutor] subclass

2006-02-03 Thread Christopher Spears
Here is a problem I'm working on out of Learning Python: Make a subclass of MyList from exercise 2 called MyListSub which extends MyList to print a message to stdout before each overloaded operation is called and counts the number of calls. MyListSub should inherit basic method behavoir from MyLi

Re: [Tutor] subclass problem: __names and type-checking

2005-10-09 Thread Brian van den Broek
Python said unto the world upon 2005-10-08 12:40: > Traceback (most recent call last): >File "C:/Python24/foofoofoo.py", line 26, in -toplevel- > s2 = Sub2() >File "C:/Python24/foofoofoo.py", line 22, in __init__ > super(Sub2, self).__init__() >File "C:/Python24/foofoofoo.py",

Re: [Tutor] subclass problem: __names and type-checking

2005-10-09 Thread Brian van den Broek
Python said unto the world upon 2005-10-08 12:32: Thanks for the response, Llyod. (And to Alan, too.) > I think that a sub-class *needs* to support the same programming > interface as the parent class. > If B inherits from A then every context where A or an A instance appears > should work co

Re: [Tutor] subclass problem: __names and type-checking

2005-10-08 Thread Alan Gauld
> If B inherits from A then every context where A or an A instance appears > should work correctly with B or a B instance. Since the B constructor > *requires* more arguments, it violates that ideal. In other words, it > would be OK to allow additional arguments. It is not OK to require > them.

[Tutor] subclass problem: __names and type-checking

2005-10-08 Thread Python
Traceback (most recent call last): File "C:/Python24/foofoofoo.py", line 26, in -toplevel- s2 = Sub2() File "C:/Python24/foofoofoo.py", line 22, in __init__ super(Sub2, self).__init__() File "C:/Python24/foofoofoo.py", line 10, in __init__ if type(self) == __TwoUnderBase: #

[Tutor] subclass problem: __names and type-checking

2005-10-08 Thread Python
I think that a sub-class *needs* to support the same programming interface as the parent class. Bertrand Meyer has written about programming by contract and the implications for object oriented design. http://archive.eiffel.com/doc/oosc/ http://se.ethz.ch/~meyer/ If B inherits from A then every c

Re: [Tutor] subclass problem: __names and type-checking

2005-10-08 Thread Brian van den Broek
Kent Johnson said unto the world upon 2005-10-08 07:08: > Brian van den Broek wrote: >> >>Here's a sketch of where I'm at: >>class _BaseClass(object): >> >> def __init__(self, arg1, arg2): >> self.arg1 = arg1 >> self.arg2 = arg2 >> if type(self) == _BaseClass: >>

Re: [Tutor] subclass problem: __names and type-checking

2005-10-08 Thread Kent Johnson
Brian van den Broek wrote: > I have a class which I want to subclass. The subclass adds some > additional arguments to __init__. I want both classes to run a sanity > check on their arguments before leaving their respective __init__ > methods. I need both to do so, as the _BaseClass may be directly

[Tutor] subclass problem: __names and type-checking

2005-10-07 Thread Brian van den Broek
Hi all, I'm having an issue which resists my attempts to give a snappy label to it. I have a solution that doesn't feel entirely correct, and which I cannot actual apply to my original case. The Issue: I have a class which I want to subclass. The subclass adds some additional arguments to __ini