我試圖定義在這個類的實例的類,使用方法在包裝功能是否有可能在Python中使用實例方法
下面是工作
代碼裝飾類的方法class A(object):
def __init__(self):
pass
@self_decorator
def to_be_decorated(self):
pass
def self_decorator(fn):
from functools import wraps
@wraps(fn)
def wrapper(*args, **kwargs):
self = args[0]
return self.app.route('/twip')(fn(*args, **kwargs))
return wrapper
我居然試圖獲得:
class A(object):
def __init__(self):
self.app = APP()
@self.app.wrapper_function # which apparently doesn't work
def to_be_decorated(self):
pass
因此,有可能是我的裝飾工作的方式嗎?
對不起,我給了一個錯誤的例子。我已更新 – yegle
@yegle我也更新了 – JBernardo