开发者

print_r functionality in iPython

开发者 https://www.devze.com 2022-12-21 03:46 出处:网络
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

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

精彩评论

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