で__call__私はPythonのデコレータを理解しようとしていたと私はこの1つに同等のプログラムを書くためにしようとしていた。Pythonのデコレータ - クラス
class myDecorator(object):
def __init__(self, f):
print ("inside myDecorator.__init__()")
f() # Prove that function definition has completed
def __call__(self):
print ("inside myDecorator.__call__()")
@myDecorator
def aFunction():
print ("inside aFunction()")
print ("Finished decorating aFunction()")
aFunction()
問題は、私はクラスの__call__
方法がどのように理解していないのですです最後にaFunction()
を呼び出すことによって呼び出されます。
aFunction()
はmyDecorator.__call__(aFunction)
に置き換えられます。 私を助けてもらえますか?デコレータのない同等のプログラムはどのようになりますか?
ありがとうございます!
関数のargsを受け入れるにはdef __call __(self、* args、** kwargs):をfに渡します – theannouncer