获取Python中的所有对象属性? [英] Get all object attributes in Python?
本文介绍了获取Python中的所有对象属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以获取所有属性/方法/字段/等. Python中的对象?
Is there a way to get all attributes/methods/fields/etc. of an object in Python?
vars()
与我想要的接近 ,但是除非对象具有__dict__
,否则它不起作用,这并不总是正确的(例如,对于dict
等).
vars()
is close to what I want, but it doesn't work unless an object has a __dict__
, which isn't always true (e.g. it's not true for a list
, a dict
, etc.).
推荐答案
Use the built-in function dir()
.
这篇关于获取Python中的所有对象属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文