0
Why the "I will be decorated" is not printed?
#Lets make a Python program def my_decorator(func): def inside(): print("Done") return func return inside @my_decorator def victim(): print("I will be decorated!") victim()
2 Réponses
+ 2
The line after a return function is not executed, so, 'return inside' won't run cos of the 'return func',that's why it only prints 'Done'.
It should be
def my_decorator(func):
def inside():
print("Done")
func()
return inside
@my_decorator
def victim():
print("I will be decorated!")
victim()
+ 2
Justus The 'return func' was actually part of the 'inside' part so it didn't really have any effect on whether 'return inside' was executed or not. The only problem was that he failed to call 'func()' as you correctly pointed out.