views:

55

answers:

4

Is there a way to get PHP-like 'print_r(object)' funcionality in iPython?

I know I can use '?' to get info about an object, but how do I view the values of the object?

A: 

repr() calls the __repr__() method of the object, which usually gives some information about the contents of the object if written appropriately.

Ignacio Vazquez-Abrams
+2  A: 

Is

print my_object.__dict__

perhaps what you are looking for?

Or have a look at the standard python pretty printer for more advanced, recursive printing.

extraneon
but don't actually name your object "object", since that has a special meaning in Python
Triptych
@Triptych I used the term that user27... also used. But I'll correct it so people new to python won't get confused.
extraneon
This one is exactly what I had in mind. Mea Culpa for using 'object'...
greg_robbins
A: 

dir(object) will give you all its attribute names.

Daniel Roseman
A: 

I'd use the pprint module if you want it to be nicely formatted:

import pprint
obj = {'a':1, 'b':2}
pprint.pprint(obj)
Triptych