How do I look inside a Python object?

Solution 1:

Python has a strong set of introspection features.

Take a look at the following built-in functions:

  • type()
  • dir()
  • id()
  • getattr()
  • hasattr()
  • globals()
  • locals()
  • callable()

type() and dir() are particularly useful for inspecting the type of an object and its set of attributes, respectively.

Solution 2:

object.__dict__