Skip to content

Instantly share code, notes, and snippets.

@qingfeng
Created June 11, 2010 07:22
Show Gist options
  • Save qingfeng/434163 to your computer and use it in GitHub Desktop.
Save qingfeng/434163 to your computer and use it in GitHub Desktop.
PyCon
from trace import traced
def tracing(cls):
cdict = cls.__dict__
for n in cdict:
if hasattr(cdict[n], "__call__") \
and not n.startswith("__"):
cdict[n] = traced(cdict[n])
return cls
if __name__ == "__main__":
@tracing
class MyClass():
def method1(self, a):
print("Method 1:", a)
def method2(self, a, b=10):
return "Method 2: %s" % (a*b)
mc = MyClass()
mc.method1("Hooray!")
print(mc.method2("Easy", b=3))
@tonyseek
Copy link

可是有 __call__ 的不一定就是方法呀…… 是不是用 descriptor 来做更好一些……

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment