Python Decorators - 3 - Hands On
Python Python Classes and Objects (Article) Python Classes and Objects (Program)
485
3. Decorators - 3
1. Define a decorator function bold_tag which adds bold HTML tags <b> function. </b> to the value of another
2. Use the Test against custom input box to output the result for debugging.
3. Provide a string (refer test case samples) to display the output/error.
Given Input:
Decorator exercise
Expected Output:
Decorator exercise
Program:
import sys
import os
#Define and implement bold_tag
def bold_tag(func):
def inner(*args, **kwdargs):
return ''+func(*args, **kwdargs)+''
return inner
def say(msg):
return msg
say=bold_tag(say)
'''Check the Tail section for input/output'''
if __name__ == "__main__":
with open(os.environ['OUTPUT_PATH'], 'w') as fout:
res_lst = list()
res_lst.append(say(input()))
fout.write("{}".format(*res_lst))
Output:
Decorator exercise
This Particular section is dedicated to Programs only. If you want learn more about Python. Then you can visit below links to get more depth on this subject.
Decorator exercise
Program:
import sys import os #Define and implement bold_tag def bold_tag(func): def inner(*args, **kwdargs): return ''+func(*args, **kwdargs)+'' return inner def say(msg): return msg say=bold_tag(say) '''Check the Tail section for input/output''' if __name__ == "__main__": with open(os.environ['OUTPUT_PATH'], 'w') as fout: res_lst = list() res_lst.append(say(input())) fout.write("{}".format(*res_lst))
Output:
Decorator exercise
This Particular section is dedicated to Programs only. If you want learn more about Python. Then you can visit below links to get more depth on this subject.