Stuck on inheritance
mis6 at pitt.edu
Wed Nov 5 08:49:12 CET 2003
"Matthew" <matthew at newsgroups.com> wrote in message news:<bo968h$bgp$1 at lust.ihug.co.nz>...
> 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:
print "I am a message"
def __init__(self, func, *args, **kw):
self.func = func
self.args = args
self.kw = kw
return self.func(*self.args, **self.kw)
def __init__(self, func, name='', info = ): # description, authour, etc
self.name = name
self.info = 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.
More information about the Python-list