If I have a function :
@aDecorator def myfunc1(): # do something here if __name__ = '__main__': # this will call the function and will use the decorator @aDecorator myfunc1() # now I want the @aDecorator to be replaced with the decorator @otherDecorator # so that when this code executes, the function no longer goes through # @aDecorator, but instead through @otherDecorator. How can I do this? myfunc1()
Is it possible to replace a decorator at runtime?
I don’t know if there’s a way to ‘replace’ a decorator once it has been applied, but I guess that probably there’s not, because the function has already been changed.
You might, anyway, apply a decorator at runtime based on some condition: