Get all object attributes in Python?

user541686 picture user541686 · Jul 31, 2011 · Viewed 470.5k times · Source

Is there a way to get all attributes/methods/fields/etc. of an object in Python?

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.).

Answer

mouad picture mouad · Jul 31, 2011

Use the built-in function dir().