Doctest and Decorators in Python
问题 I was trying to use Python decorator to catch exceptions and log the exceptions. import os.path import shutil class log(object): def __init__(self, f): print "Inside __init__()" self.f = f def __call__(self, *args): print "Inside __call__()" try: self.f(*args) except Exception: print "Sorry" @log def testit(a, b, c): print a,b,c raise RuntimeError() if __name__ == "__main__": testit(1,2,3) It works fine Desktop> python deco.py Inside __init__() Inside __call__() 1 2 3 Sorry The issue is that