【发布时间】:2018-06-11 06:44:15
【问题描述】:
我正在尝试从 python 中的另一个类调用装饰器。下面是代码
file_1.py
class ABC:
def decorate_me(func):
def wrapper():
print "Hello I am in decorate_me func"
print "Calling decorator function"
func()
print "After decorator"
return wrapper
file_2.py
from file_1 import ABC
@ABC.decorate_me
def test():
print "In test function ."
test()
输出
TypeError: unbound method decorate_me() must be called with ABC instance as first argument (got function instance instead)
【问题讨论】:
标签: python decorator python-import python-module python-decorators