[Tutor] calling the constructor of an inherited class
Don Arnold
Don Arnold" <darnold02@sprynet.com
Thu May 29 06:55:03 2003
----- Original Message -----
From: "ali mangaliag" <rmangaliag@slu.edu.ph>
To: <tutor@python.org>
Sent: Thursday, May 29, 2003 2:27 AM
Subject: [Tutor] calling the constructor of an inherited class
class x:
def __init__(self, a):
self.a = a
class x(y):
def __init__(self):
# how can i call the constructor of class x???
thanks...
ali
I believe you meant 'class y(x):' above. Anyway, you call the parent's
__init__ just like any other function:
class A:
def __init__(self,name):
self.name=name
class B(A):
def __init__(self, name, address): ## added address parameter
A.__init__(self,name)
self.address=address
me = B('Don','12345 Main St')
print me.name
print me.address
>>> Don
>>> 12345 Main St
HTH,
Don