Inheriting and modifying lots of methods

Felipe Ochoa felipeochoa0918 at
Tue Oct 27 18:43:42 CET 2009

I need to create a subclass from a parent class that has lots of
methods, and need to decorate all of these. Is there pythonic way of
doing this other than:

def myDecorator (meth):
    def newMeth (*args, **kw):
        print("Changing some arguments here.")
        return meth(newargs, **kw)
    return newMeth

class Parent:
    def method1(self,args):
    def method2(self,args):
    # and so on...
    def methodn(self,args):

class Mine(Parent):
    for thing in dir(Parent):
        if type(eval("Parent."+thing)) == type(Parent.method1):
            eval(thing) = myDecorator(eval("Parent." + thing))

I'm not even sure that this works! Thanks a lot!

More information about the Python-list mailing list