Skip to content

Instantly share code, notes, and snippets.

@PrudhviVajja
Created November 10, 2020 08:34
Show Gist options
  • Save PrudhviVajja/1db8627077d9102aaf18d61db860d792 to your computer and use it in GitHub Desktop.
Save PrudhviVajja/1db8627077d9102aaf18d61db860d792 to your computer and use it in GitHub Desktop.
SimpleDecorator
def func_name_printer(func):
def wrapper(*args):
print("Function that started running is " + func.__name__)
func(*args)
return wrapper
def add(*args):
tot_sum = 0
for arg in args:
tot_sum += arg
print("result = " + str(tot_sum))
sample = func_name_printer(add)
# ex 1
sample(1,2)
# Function that started running is add
# result = 3
# ex 2
sample(1,2,3)
# Function that started running is add
# result = 6
# ex 3
sample(1,2,3,4)
# Function that started running is add
# result = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment