How do I add a method with a decorator to a class? I tried
def add_decorator( cls ):
@dec
def update(self):
pass
cls.update = update
usage
add_decorator( MyClass )
MyClass.update()
but MyClass.update does not have the decorator
@dec did not apply to update
I’m trying to use this with orm.reconstructor in sqlalchemy.
If you want class decorator in python >= 2.6 you can do this
or in python 2.5
But looks like you are interested in method decorator, for which you can do this
Output:
So in short you have to just put
@orm.reconstructorbefore method definition