现在,我们可以使用.pprint()对象或实例化我们自己的pprint对象PrettyPrinter()。 代码语言:javascript 代码运行次数:0 运行 AI代码解释 pprint.pprint(['Radha',1,'Hari','Simesh',25,847])# Instantiating pprint object my_pprint=pprint.PrettyPrinter()my_pprint.pprint(['Radha',1,'Hari','Simesh',25,84...
假设我们用print()打印一些复杂的嵌套数据, 一旦我们开始处理多层嵌套的数据结构,print()就变得一团糟。 使用pprint()替代print() pprint模块是 Python 标准库的一部分,这意味着我们不需要安装任何东西,只需导入即可。 在pprint模块中,有一个名为pprint的函数(是的,它们同名)。pprint是 "pretty-print" 的缩写,意思...
如果定制类定义了一个__repr__()方法,pprint()使用的PrettyPrinter类还可以处理这些定制类。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from pprint import pprint class node(object): def __init__(self,name,contents =[]): self.name = name self.contents = contents[:] def __repr__(self...
stream —指输出流对象,如果stream=None,那么输出流对象默认是sys.stdout 2.pprint.pformat(object,indent=1,width=80, depth=None) 返回格式化的对象字符串 3.pprint.pprint(object,stream=None,indent=1, width=80, depth=None) 输出格式的对象字符串到指定的stream,最后以换行符结束。 4.pprint.isreadable(obje...
('fresh fruit',)))# Using PrettyPrinterpp=pprint.PrettyPrinter(depth=6) # default configuration# of depthbeing none is changed todepth=6# Now it will print till depth of six bracketspp.pprint(tuple1)#Using only pprint() objectpprint.pprint(pprint.pprint(tuple1,depth=6))pprint.pprint(tuple...
class(NormalClassNewStyle):dicts:{},lists:[],static_props:1,tuple:(1,2) pprint: <definition.NormalClassNewStyleobjectat0x7f338e5a9dd0> beeprint: instance(NormalClassNewStyle):dicts:{},lists:[],say_hi:'hello world',static_props:1,tuple:(1,2) ...
class(NormalClassNewStyle):dicts:{ },lists:[],static_props:1,tuple:(1,2) pprint: <definition.NormalClassNewStyle objectat0x7f338e5a9dd0> beeprint: instance(NormalClassNewStyle):dicts:{ },lists:[],say_hi:'hello world',static_props:1,tuple:(1,2) ...
可自定义配置的内容查阅pretty_errors/__init__.py的class PrettyErrorsConfig或运行代码 import pretty_errors def print_object(obj): print('\n'.join(['%s:%s' % item for item in obj.__dict__.items()])) print_object(pretty_errors.default_config) ...
Any class object can define a__pout__magic method, similar to Python's built in__str__magic method that can return a customized string of the object if you want to. This method can return anything, it will be run through Pout's internal stringify methods to convert it to a string and...
function is a replacement for built in print, all arguments other than strings are pretty printed. class pprintex.PrettyPrintCfg configuration object for the pretty printer. has the following static members. indent_string default value ' '; for each indentation level displays this string, can sw...