+ 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))
4 ответов
+ 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))
+ 9
return text.upper() instead of printing it in the decorator
+ 5
Thank you Frogged and Slick. I both understand the exercise and why using return rather than print.thank you
+ 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))