def info(a):
for m in dir(a):
if callable(getattr(a, m)):
print m + ' is member function'
else:
print m + ' is a member'因此将文本转换成为代码一般依靠 getattr。另外可以通过 types 中的 FunctionType 判断是否为函数。通过将对象的方法放在字符串里面就可以把一些行为 encode 在文件中。