0
私はこのようなシンプルなデコレータを持っています。しかし、私はPythonファイルをインポートするとすぐに実行され、私は再び関数を呼び出すことはできません。デコレータはどのように使用されるのですか?別のファイルでデコレータを読み込んで使用する
def plain_decorator(func):
def decorated_func():
print "Decorating"
func()
print "Decorated"
return decorated_func()
@plain_decorator
def hw():
print "Hello Decorators!"
>>> import decorator_ex2 as d
Decorating
Hello Decorators!
Decorated
>>> d.hw()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
>>>