现在,我们可以使用.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...
('parrot', ('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...
Note that the arguments you passed toPrettyPrinterare exactly the same as the defaultpprint()arguments, except that you skipped the first parameter. Inpprint(), this is the object you want to print. This way, you can have various printer presets—perhaps some going to different streams—and ...
('parrot', ('fresh fruit',))) #UsingPrettyPrinter pp=pprint.PrettyPrinter(depth=6) #defaultconfiguration #ofdepthbeingnoneischangedtodepth=6# Now it will print till depthofsix brackets pp.pprint(tuple1) #Usingonlypprint() object pprint.pprint(pprint.pprint(tuple1, depth=6)) pprint.pprint(...
pprint对字典 列表这类数据结构确实很好用,但遇到类、字符串仍然和 print 差别不大,因此这里有一个国人写的第三方库介绍给大家。 beeprint 除了和 pprint 一样支持 dict, list, tuple 等常规变量的格式化输出,还支持 object 变量打印、长文本自动剪切。
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(object) 判断对象object的字符串对象是否可读 ...
pprint对字典 列表这类数据结构确实很好用,但遇到类、字符串仍然和 print 差别不大,因此这里有一个国人写的第三方库介绍给大家。 beeprint 除了和 pprint 一样支持 dict, list, tuple 等常规变量的格式化输出,还支持 object 变量打印、长文本自动剪切。
6.pprint.saferepr(object) 返回一个对象字符串,对象中的子对象如果是可递归的,都被替换成<Recursionontypenamewithid=number>.这种形式。 PrettyPrinter 对象具有的方法与上面类似,不在赘述。 importpprint data = ( "this is a string", [1,2,3,4], ("more tuples", ...
pprint.pprint(object, stream=None, indent=1, width=80, depth=None, *, compact=False) stream:输出流,默认是 sys.stdout ,也就是屏幕输出。 indent:缩进空格数。 width:每行最大宽度,默认为80个字符,超过宽度会换行,但如果单个对象超过不会被换行,比如一段长字符串。
6.pprint.saferepr(object) <Recursionontypename withid=number>.这种形式。 PrettyPrinter 对象具有的方法与上面类似,不在赘述。 1. import pprint 2. 3. data = ( 4. "this is a string", [1, 2, 3, 4], ("more tuples", 5. 1.0, 2.3, 4.5), "this is yet another string" ...