[Tutor] subclass / superclass methods

Dragonfirebane at aol.com Dragonfirebane at aol.com
Wed Jun 30 23:55:08 EDT 2004


I, too, am farily new at Python, but it occurs to me that perhaps you meant 
to have

class object:
    def __init__(self):
        print 'Hello object __init__'
    def EventTick(self):
        print 'Hello object EventTick'
        self.OnTick()
    def OnTick(self):
        print 'Hello object OnTick'
class other(object):
    def __init__(self):
        print 'Hello other __init__'
    def OnEvent(self):
        print 'Hello other OnTick'
if __name__ == '__main__':
    my = other()
    my.EventTick()

be

class object:
    def __init__(self):
        print 'Hello object __init__'
    def EventTick(self):
        print 'Hello object EventTick'
        self.OnTick()
    def OnTick(self):
        print 'Hello object OnTick'
class other(object):
    def __init__(self):
        print 'Hello other __init__'
    def OnTick(self):
        print 'Hello other OnTick'
if __name__ == '__main__':
    my = other()
    my.EventTick()

(change OnEvent(self) in Class other to OnTick(self) so that when 
my.EventTick() is run, it goes to Class other's OnTick rather than Class object since 
Class other's OnTick wouldn't exist)

the proposed change produces the following in IDLE:

Hello other __init__
Hello object EventTick
Hello other OnTick

I don't know if that's what you wanted, but it has "Hello other OnTick" in it.

Email: dragonfirebane at aol.com
AIM: singingxduck
Programming Python for the fun of it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040630/1ed1bee2/attachment.html


More information about the Tutor mailing list