[General lang] how to call a parent
Helmut Jarausch
jarausch at skynet.be
Sun Jun 15 12:55:01 EDT 2003
John Fabiani wrote:
> I'm a newbie to the Python world but not programming. In the Visual Foxpro
> world we have the concept of ?parent?. I normally use it to set
> properties of a custom control as in ?parent.background.color = blue?.
> The parent in this case is a container. In the VFP world we have
> ?thisform, this, and parent? and all class methods are run unless
> overwritten by the child class. Anyway, I'd know how to call the parent of
> an object. BTW if I'm all wrong with this idea would someone explain why!
>
By using either the name of the parent class or by using 'super' for
Python >= 2.2
class A(object) :
def prt(self) :
print "This is class A"
class B(A) :
def prt(self) :
print "This is class B"
A.prt(self)
print "using super:"
super(B,self).prt()
I_B= B();
I_B.prt()
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
More information about the Python-list
mailing list