print_r functionality in iPython
Question
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?
Solution
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.
OTHER TIPS
dir(object)
will give you all its attribute names.
I'd use the pprint
module if you want it to be nicely formatted:
import pprint
obj = {'a':1, 'b':2}
pprint.pprint(obj)
repr()
calls the __repr__()
method of the object, which usually gives some information about the contents of the object if written appropriately.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow