From 41262fc75551d35bcc9979011078b0e5b4e7b36a Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sat, 28 Nov 2020 13:25:53 -0800 Subject: [PATCH] Adds decorators --- decorators.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 decorators.py diff --git a/decorators.py b/decorators.py new file mode 100644 index 0000000..7a08879 --- /dev/null +++ b/decorators.py @@ -0,0 +1,24 @@ +from datetime import datetime +import functools + +def invokation_logged(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + now = datetime.now() + timestamp = now.strftime("%d-%b-%Y (%H:%M:%S.%f)") + print("%s(%s): Entered function" % (func.__name__, timestamp)) + ret = func(*args, **kwargs) + now = datetime.now() + timestamp = now.strftime("%d-%b-%Y (%H:%M:%S.%f)") + print("%s(%s): Exited function" % (func.__name__, timestamp)) + return ret + return wrapper + +# Test +#@invokation_logged +#def f(x): +# print(x * x) +# return x * x +# +#q = f(10) +#print(q) -- 2.45.2