Stuck on inheritance

Matthew matthew at newsgroups.com
Tue Nov 4 22:44:50 CET 2003


Hi,

I'm trying to learn python and actually do something usefule with it at the
same time. I'm unclear how you correctly pass arguments to a superclass when
ining the subclass. Below is a short code fragment. What's wrong? Thanks
alot. matthew.

def print_message():
    print "I am a message"

class call_me(object):
    def __init__(self, func, *args, **kw):
        self.func = func
        self.args = args
        self.kw = kw

    def __call__(self):
        print "Execing..."
        return self.func(*self.args, **self.kw)

class function(call_me):
    def __init__(self, name='', info = []): # description, authour, etc
        super(call_me, self).__init__()
        self.name = name
        self.info = info

a_call_me = call_me(print_message)
a_call_me()
func = function(a_call_me, 'fred', [])
# also tried func = function(call_me(print_message), 'fred', [])
func()







More information about the Python-list mailing list