How do I look inside a Python object?

littlejim84 picture littlejim84 · Jun 17, 2009 · Viewed 335.3k times · Source

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?

Answer

Brandon E Taylor picture Brandon E Taylor · Jun 17, 2009

Python has a strong set of introspection features.

Take a look at the following built-in functions:

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