在Python里,当调用一个对象的方法,而这个方法不存在时,会抛出错误,
有没有一个方法,当调用不存在的方法时,就会调用某个特定的函数?
比如说methodNotFound()方法
def readImage(fp):
if hasattr(fp, read ):
return readData(fp)
return None可以使用__getattr__方法解决
class Foo(object):
def __getattr__(self, key):
return lambda: pythontab
f = Foo()
print f.python()好方法,感谢