0

How can upper() works in wrapper?

I can’t get why below codes doesn’t work. Help me, somebody. —- text = input() def uppercase_decorator(func): def wrapper(func): func.upper() #your code goes here return wrapper @uppercase_decorator def display_text(text): return(text) print(display_text(text))

22nd Sep 2021, 12:00 PM
Taka
Taka - avatar
3 odpowiedzi
+ 2
I see people doing the same mistake. Now i wonder why are you all jumping to decorator functions using (@) if you can't understand how it's actually implemented. You should pass argument name(any random name ) to wrapper function instead of the function name(func is the display_text function name). Your uppercase_decorator function should look like this, def uppercase_decorator(func) : def wrapper(t): func(t).upper() return wrapper
22nd Sep 2021, 12:41 PM
Abhay
Abhay - avatar
+ 1
Taka use return keyword at line no 5. to return func.upper() returned string. https://code.sololearn.com/cEYet7syAU9e/?ref=app
22nd Sep 2021, 4:16 PM
I Am a Baked Potato
I Am a Baked Potato - avatar
0
Finally, I've got it! Thanks guys!
19th Oct 2021, 10:22 AM
Taka
Taka - avatar