Decoration Time vs Call Time
def count_calls(func):
print(f"decorating {func.__name__}")
calls = 0
def wrapper(*args, **kwargs):
nonlocal calls
calls += 1
print(f"{func.__name__} call #{calls}")
return func(*args, **kwargs)
return wrapper
@count_calls
def ping():
return "pong"
@count_calls
def pong():
return "ping"
print("--- module loaded, now calling ---")
ping()
ping()
pong()
What does running this module print, in order?
Sign in to answer questions and track your progress
Sign In