Stuck on inheritance

zsolt zsolt-public1192 at mailblocks.com
Wed Nov 5 05:45:45 CET 2003


I too am very new to the concept of classes and inheritance in python.
 I do not have a grasp on how to use "super",nor do I think it is well
documented.  The below code alterations shows how I learned to
subclass.

I may not have a complete grasp of what you were trying to do because
I had to add .func to a_call_me where you instanciated function. 
Also,I added args to print_message, to get the the args you are adding
passed through.  Anyway, I hope I'm not too off the mark.

def print_message(*args, **kw):
    print "I am a message"
    print args, kw

    
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, func, name='', info = []): # description,
authour, etc
        call_me.__init__(self, func, name, info)
        self.name = name
        self.info = info


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




More information about the Python-list mailing list