decorator pattern the code we want should look something like this@profile_all_class_methods class domathstuff(object)def fib(self)@profiling_decorator def factorial(self)in essencewhat we want is class that looks exactly like the domathstuff class from the outsidewith the only difference being that every method call should be profiled the profiling code we wrote in the previous section should still be of useso let' take that and make the wrapping function more general so it will work for any function passed to it import time def profiling_wrapper( )@wraps(fdef wrap_f(*args**kwargs)start_time time time(result (*args**kwargsend_time time time(elapsed_time end_time start_time print("[time elapsed for {}{}format(nelapsed_time)return result return wrap_f we received two packed argumentsa list of regular arguments and list of arguments mapped to keywords between themthese two arguments will capture any form of argument that can be passed to python function we also unpack both as we pass them on to the function to be wrapped nowwe want to create class that would wrap class and apply the decorating function to every method in that class and return class that looks no different from the class it received this is achieved through the __getattribute__(magic method python