Created
January 10, 2014 20:58
-
-
Save addisaden/8362478 to your computer and use it in GitHub Desktop.
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
class A: | |
def hallo(self): | |
return "Hallo Welt" | |
def logger(obj, methodname): | |
tmp_method = getattr(obj, methodname) | |
def tmp_logger(*args): | |
print("Open:", methodname) | |
result = tmp_method(*args) | |
print("Closing:", methodname) | |
return result | |
setattr(obj, methodname, tmp_logger) | |
a = A() | |
b = A() | |
logger(b, "hallo") | |
print("----------\nprint(a.hallo())") | |
print(a.hallo()) | |
print("----------\nprint(b.hallo())") | |
print(b.hallo()) | |
print("----------\nprint(a.hallo())") | |
logger(A, "hallo") | |
print(a.hallo()) | |
# ---------- | |
# print(a.hallo()) | |
# Hallo Welt | |
# ---------- | |
# print(b.hallo()) | |
# Open: hallo | |
# Closing: hallo | |
# Hallo Welt | |
# ---------- | |
# print(a.hallo()) | |
# Open: hallo | |
# Closing: hallo | |
# Hallo Welt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment