Basic Inheritance Question

Curzio Basso curzio.basso at unibas.ch
Fri Mar 19 07:15:34 EST 2004


Matthew Bell wrote:

> Essentially, then, if I've inherited another class, how 
> do I create an instance of the class I've inherited such 
> that methods I haven't overrriden will still work, and 
> how can I then refer to that instance from my subclass?  
> I can guess it's something to do with "self" but exactly 
> what, I'm really at a loss.

If I got it right, you should have:

class A:
   def __init__(self):
     self.data=[]

class B(A):
   def __init__(self):
     A.__init__(self)
     self.data=[1,2,3]

cheers



More information about the Python-list mailing list