+ 2

Python class - decorator

Hi, I want to display the upper case of a text using a decorator. I only added the line related to the upper case, other parts of the code are imposed. I get forr instance : hello as input Output: HELLO None How can I get rid of the None? Thank you. Code : text = input() def uppercase_decorator(func): def wrapper(text): #your code goes here print(text.upper ()) return wrapper @uppercase_decorator def display_text(text): return(text) print(display_text(text))

25th Sep 2020, 12:31 PM
Sob Xav
Sob Xav - avatar
4 Réponses
+ 25
text = input() def uppercase_decorator(func): def wrapper(text): #your code goes here return(text.upper ()) return wrapper @uppercase_decorator def display_text(text): return(text) print(display_text(text))
25th Sep 2020, 12:39 PM
Oma Falk
Oma Falk - avatar
+ 9
return text.upper() instead of printing it in the decorator
25th Sep 2020, 12:38 PM
Slick
Slick - avatar
+ 5
Thank you Frogged and Slick. I both understand the exercise and why using return rather than print.thank you
25th Sep 2020, 2:28 PM
Sob Xav
Sob Xav - avatar
+ 2
You could also try this out: text = input() def uppercase_decorator(func): def wrapper(text): #your code goes here return func(text).upper() return wrapper @uppercase_decorator def display_text(text): return(text) print(display_text(text))
12th May 2021, 8:59 AM
Joseph Kivengere