i have a simple decorator,the output confused me.
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.
i know the output of myfunc(),but the output of deco(myfunc)() confused me,whay the output of deco(myfunc)() can not be either of them in the following?
status one:
before myfunc() called.
before myfunc() called.
myfunc() called.
myfunc() called.
after myfunc() called.
after myfunc() called.
status two:
before myfunc() called.
myfunc( deco(myfunc)()) called.
after myfunc() called.
before myfunc() called.
myfunc( deco(myfunc)()) called.
after myfunc() called.