Если у меня есть функция:Возможно ли заменить декоратор функции/метода во время выполнения? [Питон]
@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()
Можно ли заменить декоратора во время выполнения?
Но это не изменит myfunc1(). – 2009-03-13 13:48:58
Я попытался использовать ваш код, функция все еще выполняется с помощью начального декоратора. – Geo
Вау .. не ожидал, что это произойдет. – miya