From ac67b302842c344270b1eccd4c74105735ffa555 Mon Sep 17 00:00:00 2001 From: bt3 Date: Sun, 24 Jun 2018 13:22:15 -0700 Subject: [PATCH] Add a useful way to understand python decorator --- source_code/learning/decorator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 source_code/learning/decorator.py diff --git a/source_code/learning/decorator.py b/source_code/learning/decorator.py new file mode 100644 index 0000000..8ef04f3 --- /dev/null +++ b/source_code/learning/decorator.py @@ -0,0 +1,19 @@ +#!/bin/python +# +# An example of Python Decorator +# + +def pretty_sumab(func): + def inner(a,b): + print(str(a) + " + " + str(b) + " is ", end="") + return func(a,b) + + return inner + +@pretty_sumab +def sumab(a,b): + summed = a + b + print(summed) + +if __name__ == "__main__": + sumab(5,3) \ No newline at end of file