0

Decorator function not working

Hi there, can someone help why is my decorator function not working? The output of this is ‘None’, but I expect it to be an uppercase of the Input text. text = input() def uppercase_decorator(func): def wrapper(t): func(t.upper()) return wrapper @uppercase_decorator def display_text(text): return(text) print(display_text(text))

10th Aug 2021, 8:33 AM
Ben
6 ответов
+ 2
Abs Sh is this what u mean? It works now :) text = input() def uppercase_decorator(func): def wrapper(text): return func(text).upper() #your code goes here return wrapper @uppercase_decorator def display_text(text): return(text) print(display_text(text))
10th Aug 2021, 9:13 AM
Ben
+ 2
You need to return the value because your argument function 'display_text' is returning a value Look the following: ... return func(t.upper()) ... print(display_text(text)) ... Just experiment here: https://code.sololearn.com/cqeQuldcDAEk/?ref=app I hope this solve your problem.
10th Aug 2021, 12:41 PM
CLAD
CLAD - avatar
+ 1
when you call function display_text(text) , it actually calls the wrapper function inside the decorator. func is the actual display_text function here that you need to print , i.e. print(func(t.upper)). And since this wrapper doesn't returns anything , using print on it returns None.
10th Aug 2021, 9:06 AM
Abhay
Abhay - avatar
0
@abhay iunderstand, but can someone explain why my code doesn’t work as intended?
10th Aug 2021, 9:02 AM
Ben
0
U not returning the func in wrapper
10th Aug 2021, 9:08 AM
Abs Sh
Abs Sh - avatar
- 1
@ahbag but why is the output of my code None?
10th Aug 2021, 9:08 AM
Ben