[Tutor] calling a superclass method after overriding it

Serdar Tumgoren zstumgoren at gmail.com
Tue Sep 22 18:47:08 CEST 2009


Hi everyone,
Is there a way to call a superclass method after I've overridden it in
a subclass?

Specifically, what I'm trying to is something like the following:

class Parent(object):
    def add_name(self):
        self.name = result_of_GENERIC_SQLcall()

class Child(Parent):
    def __init__(self):
        super(Child, self).__init__()

    def add_name(self):
        name = result_of_SPECIALIZED_SQLcall_for_child()
        try:
            name + ''
            self.name = name
        except TypeError:
            #default to the superclass's add_name method
            Base.add_name()

My key point of confusion is in the except clause: I'm not sure of the
syntax for calling the original superclass method (or if it's even
possible). Can anyone point me in the right direction?

Regards,
Serdar


More information about the Tutor mailing list