+ 2
Why not print 4,2 and 7
def my_decorator(some_function): print(6) def wrapper(): some_function() print(2) print(1) return wrapper print(4) @my_decorator def func(): print(7) my_decorator(func)
2 Réponses
+ 5
def my_decorator(some_function):
print(6)
def wrapper():
some_function()
print(2)
print(1)
return wrapper
print(4)
@my_decorator
def func():
print(7)
func()
4 will never be printed because it is unreachable (after a return statement)
+ 1
return wrapper(), not return wrapper. Cotents of wrapper() (some_function() which is 7 and 2) wont be printed. 4 cant be printed since its after a return.