私はデコレータの機能を理解しようとしています。次のコードで何が間違っているのですか?それを修正してください。デコレータのpython
私が理解しているように、aFunction()が呼び出されると、これもまた、myDecorator()を呼び出して、これもまた、afunction()を呼び出します。右? __init__
で
またafunctionにパラメータを渡す方法()
class myDecorator(object):
def __init__(self, f):
print "inside myDecorator.__init__()"
f(1) # Prove that function definition has completed
def __call__(self):
print "inside myDecorator.__call__()"
@myDecorator
def aFunction(*a):
print a
print "inside aFunction()"
print "Finished decorating aFunction()"
aFunction(2)
徹底解説:http://stackoverflow.com/questions/739654/understanding-python-decorators – rplnt
あなたはデコレータや注釈でより多くの助けが必要な場合は、ここで私のブログの記事を参照してください。 http://blog.mattalcock.com/2013/1/5/decorates-and-annotations/ –