Practice #1
Lesson 8 of 12 in Coddy's Python Decorators course.
To wrap a function with not known number of arguments use,
def decorator(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return result
return wrapperChallenge
EasyWrite a decorator called timing_decorator that prints the execution time of a function in seconds, rounded to 1 decimal points.
For example, if the decorated function named foo takes 2.5 seconds to execute, the decorator should print "foo took 2.5 seconds to execute".
You can use the time library to get the current clock time,
import time
start = time.time()
# Some operations
end = time.time()
diff = end - start # execution time of "operations"Try it yourself