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
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
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
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
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
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
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
__
"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
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
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
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
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
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
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
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",
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
> 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.
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: #
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
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:
>>
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
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
22 matches
Mail list logo