看这样一个例子:
例子中重载了getattr方法, 随后book这个类就可以支持任意方法了。
实际过程应该是系统自动的调用上述方法获取一个 函数 然后调用这个函数。
'''
Created on 2016-5-4
@author: Administrator
'''
import time
class Book:
def hello(self,next='Default'):
print 'helo',next
return 'hello '+next
def __getattr__(self,name):
print 'name'
return self.hello;
book = Book();
book.sss()
book.bbb()
book.eee()
book.ddd()
print book['ss']