开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜