('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...
现在,我们可以使用.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...
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(...
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) <Recursionontypename withid=number>.这种形式。 PrettyPrinter 对象具有的方法与上面类似,不在赘述。 AI检测代码解析 1. import pprint 2. 3. data = ( 4. "this is a string", [1, 2, 3, 4], ("more tuples", ...
6.pprint.saferepr(object) 返回一个对象字符串,对象中的子对象如果是可递归的,都被替换成<Recursionontypenamewithid=number>.这种形式。 PrettyPrinter 对象具有的方法与上面类似,不在赘述。 importpprint data = ( "this is a string", [1,2,3,4], ("more tuples", ...
使用pprint 模块的 pprint() 替代 print(),可以解决如下痛点: 设置合适的行宽度,作适当的换行 设置打印的缩进、层级,进行格式化打印 判断对象中是否有无限循环,并优化打印内容 1、简单使用 语法:pprint(object, stream=None, indent=1, width=80, depth=None, *,compact=False) ...
然后,不要像上面的例子那样采用一般的print(users)方法,可以调用这个优雅的函数pprint(users)来使输出更加美观。 这个函数以一种新的和改进的pretty的方式打印用户数据。 pprint(users) [{'WeChat': 'Mr_cloud_data', 'address': {'city': 'chengdu', 'geo': {'lat': '102.54', 'lng': '30.05'}}, ...