How do I look inside a Python object?

introspection, python

Solution

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.

Problem

I'm starting to code in various projects using Python (including Django web development and Panda3D game development). To help me understand what's going on, I would like to basically 'look' inside the Python objects to see how they tick - like their methods and properties. So say I have a Python object, what would I need to print out its contents? Is that even possible?

Original source

Related problems