I have a question with the application of decorators.
I understand that a decorator is a function that receives another function as a parameter and "wraps" it. But if this function has to return a value ( return
) it returns it as None
. However, with print
it works without problems.
I do not understand well why func1 works without problems and func2 not:
# EJEMPLO BÁSICO DE DECORADOR 1
def decorador(func):
def wraper(*args,**kwargs):
print ("inicio de función")
func(*args, **kwargs)
print ("Final de función")
return wraper
@decorador
def func1(text):
print (text)
@decorador
def funz2(text):
return (text)
func1("función 1")
a = funz2("función 2")
print (a)
The result is:
inicio de función
función 1
Final de función
inicio de función
Final de función
None