Stuck on inheritance

Michele Simionato mis6 at
Wed Nov 5 08:49:12 CET 2003

"Matthew" <matthew at> wrote in message news:<bo968h$bgp$1 at>...
> 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? 

The following works:

def print_message():
    print "I am a message"
class call_me(object):
    def __init__(self, func, *args, **kw):
        self.func = func
        self.args = args = kw
    def __call__(self,*args,**kw):
        print "Executing..."
        return self.func(*self.args, **
class funct(call_me):
    def __init__(self, func, name='', info = []): # description, authour, etc
        super(funct, self).__init__(func,name,info) = name = info

a_call_me = call_me(print_message)
func = funct(a_call_me, 'fred', [])

I am not sure what you are trying to do, so I followed  your original
code. Your mistake was in super. There was also a problem in
__call__: do you want it to receive zero arguments or a variable
number of arguments? You must be consistent since __call__ and
func must have the same signature in order your code to work.

Notice that "function" is a built-in, so I changed it to "funct".
Moreover, you should use capital names for classes. Finally,
using info=[] is risky: the standard idiom is

if info is None: info=[]

The reason is that lists are mutables; if you Google on the
newsgroup you will find hundreds of posts explaining the issue.

              Michele Simionato

More information about the Python-list mailing list