Add a useful way to understand python decorator

This commit is contained in:
bt3 2018-06-24 13:22:15 -07:00
parent 3cc8c1d5c0
commit ac67b30284

View File

@ -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)