Skip to content

Instantly share code, notes, and snippets.

@contee213
Created September 9, 2014 16:13
Show Gist options
  • Save contee213/166d7c05b8c3b6426bb6 to your computer and use it in GitHub Desktop.
Save contee213/166d7c05b8c3b6426bb6 to your computer and use it in GitHub Desktop.
deco
def log(f):
def wrapper():
try:
print("in")
return f()
finally:
print("out")
return wrapper
def logvar(text):
def deco(f):
def wrapper():
try:
print("in", text)
return f()
finally:
print("out", text)
return wrapper
return deco
@log
def func1():
print("func1")
@logvar("test")
def func2():
print("func2")
def func3():
print("func3")
func1()
func2()
deco = logvar("test")
func3 = deco(func3)
func3()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment