Dec-02-2022, 05:32 PM
(This post was last modified: Dec-02-2022, 05:41 PM by Yoriz.
Edit Reason: Added code tags
)
import time def time_master(func): def call_func(): print("start program") start = time.time() func() stop = time.time() print(f"it take {stop - start}second.") return call_func def myfunc(): time.sleep(2) print('I love fishc') myfunc=time_master(myfunc) myfunc()Hey, I am learning python, and I am confused with this code, this code create some functions to detect the times of runing other functions. However, in this case, at the end of the code, myfunc should equal to time_master(myfunc) right? so I believe when myfunc() recall the time_master function, in the time_master function -call_func() part, the myfunc function will be run again and start another time_master(myfunc) . Which will lead into an infinite loop, but it actually does not, can someone explain the reasons for me? thanks