【发布时间】:2011-09-20 11:40:45
【问题描述】:
当我为类方法创建装饰器时,它总是接收类型为“函数”的方法。
但是,当我稍微玩弄一些东西时,我只能返回绑定方法:
class Test(object):
def save(self):
print "Save called"
def func(self):
print "Func called"
然后:
>>> type(Test.func)
<type 'instancemethod'>
>>> type(Test().func)
<type 'instancemethod'>
我最终想做的是创建一个类方法装饰器,它还装饰同一个类上的一些其他方法。我该怎么做呢?
【问题讨论】:
-
Test.func不是绑定方法。
标签: python