+ 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)

16th Jun 2019, 7:28 PM
kokito
2 odpowiedzi
+ 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)
16th Jun 2019, 7:59 PM
Anna
Anna - avatar
+ 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.
17th Jun 2019, 2:43 AM
Choe
Choe - avatar