How do I look inside a Python object?
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.
I'm surprised no one's mentioned help yet!
In [1]: def foo(): ...: "foo!" ...:In [2]: help(foo)Help on function foo in module __main__:foo() foo!
Help lets you read the docstring and get an idea of what attributes a class might have, which is pretty helpful.