Inheriting and modifying lots of methods
Felipe Ochoa
felipeochoa0918 at gmail.com
Tue Oct 27 13:43:42 EDT 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):
@wraps(meth)
def newMeth (*args, **kw):
print("Changing some arguments here.")
return meth(newargs, **kw)
return newMeth
class Parent:
def method1(self,args):
pass
def method2(self,args):
# and so on...
def methodn(self,args):
pass
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