print_r functionality in iPython
Is there a way to get PHP-like print_r(object)
funcionality in iPython?开发者_StackOverflow
I know I can use '?' to get info about an object, but how do I view the values of the object?
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.
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.
精彩评论