Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Consider the following program: def my decorator (func_to_decorate): def my wrapper (*args, **kwargs): print (In wrapper, wrapping ()* .format(func_to_decorate_name)) result func_to_decorate (*args, **kwargs)
2. Consider the following program: def my decorator (func_to_decorate): def my wrapper (*args, **kwargs): print ("In wrapper, wrapping ()* .format(func_to_decorate_name)) result func_to_decorate (*args, **kwargs) print ("Still in wrapper, returning wrapped {}* .format(func_to_decorate.____name___)) return result return my wrapper my decorator def add list (int list): result sum: 0 for num in int list: result sum = result sum + num print ("In add list1, res is (}".format(result_sum)) return result_sum def add list2 (int_list): return sum(int list) add list2 my decorator (add list2) my decorator def print stuff (str_var): print ("In print stuff...") return "print stuff, val is (}".format(str_var) int list list (range (5)) print (add list (int_list)) print (add list2 (int_list)) print (print stuff("random junk")) (a) Describe the purpose and use of a decorator function. Your answer should include a description of what happens when a function is "decorated". (13 marks) (b) Describe what happens when the program is run. What results are produced? comment on the way add_list2 is called as opposed to the way add_listl is called. (8 marks) (c) Describe the use of the @property syntax in the context of an instance variable of an object. (8 marks) (d) Describe the purpose and use of the *args and **kwargs parameters in the program. What is the content of _name_in func_to_decorate._name_? Why would you use this variable?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started