Created
September 9, 2014 16:13
-
-
Save contee213/166d7c05b8c3b6426bb6 to your computer and use it in GitHub Desktop.
deco
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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