Nếu tôi có một chức năng:Có thể thay thế một trình trang trí hàm/phương thức trong thời gian chạy không? [Python]
@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()
Có thể thay thế một trang trí trong thời gian chạy?
Nhưng điều này sẽ không thay đổi myfunc1(). –
Tôi đã thử sử dụng mã của bạn, hàm vẫn thực thi với trình trang trí ban đầu. – Geo
wow .. không mong đợi điều này xảy ra. – miya