私は単純なデコレータを持っていますが、出力は私を混乱させました。
def deco(func):
def kdeco():
print("before myfunc() called.")
func()
print(" after myfunc() called.")
return kdeco
@deco
def myfunc():
print(" myfunc() called.")
myfunc()
before myfunc() called.
myfunc( deco(myfunc)()) called.
after myfunc() called.
deco(myfunc)()
before myfunc() called.
before myfunc() called.
myfunc() called.
after myfunc() called.
after myfunc() called.
私は myfunc() の出力を知っていますが、deco(myfunc)() の出力は私を混乱させました。なぜ deco(myfunc)() の出力は次のどちらにもならないのですか?
ステータス 1:
before myfunc() called.
before myfunc() called.
myfunc() called.
myfunc() called.
after myfunc() called.
after myfunc() called.
ステータス 2:
before myfunc() called.
myfunc( deco(myfunc)()) called.
after myfunc() called.
before myfunc() called.
myfunc( deco(myfunc)()) called.
after myfunc() called.