One - One Code All

Blog Content

python获得一个对象的所有属性和方法dir()

Python   2014-04-23 00:17:55

dir()函数,它返回一个包含字符串的list,比如,获得一个str对象的所有属性和方法:

print(dir('obj'))


配合getattr()、setattr()以及hasattr(),我们可以直接操作一个对象的状态。


上一篇:python字典复制,赋值与拷贝
下一篇:python3中dict.items代替python2的iteritems

The minute you think of giving up, think of the reason why you held on so long.