class Foo:
"""
; 反射示例
"""
def a(self):
return 'this is function a'
def b(self):
return 'this is function b'
inp = input('Please input function: ')
if hasattr(Foo(), inp): # 输入值是类中方法 True
func = getattr(Foo(), inp) # 得到类方法内存地址
ret = func() # 执行类方法
print(ret)
else:
print('404')