pprint English full name Data pretty printer, Just as the name suggests, it makes the display result more beautiful .
print() and pprint() All are python Print module for , The function is basically the same , The only difference is pprint() The data structure printed out by the module is more complete , Each row has a data structure , Easier to read printouts . Especially for very long data printing ,print() The output results are all on one line , Inconvenient to view , and pprint() Use branch printout , Therefore, the data structure is more complex 、 Data with long data length , Suitable for adoption pprint() Printing method . Of course , In general, most of them use print().
Code example :
import pprint
data=['generate_csv\\train_00.csv','generate_csv\\train_01.csv',
'generate_csv\\train_02.csv', 'generate_csv\\train_03.csv',
'generate_csv\\train_04.csv', 'generate_csv\\train_05.csv',
'generate_csv\\train_06.csv', 'generate_csv\\train_07.csv',
'generate_csv\\train_08.csv', 'generate_csv\\train_09.csv',
'generate_csv\\train_10.csv', 'generate_csv\\train_11.csv']
print(data)
print("-------- Demarcation line --------------")
pprint.pprint(data)
Code run results :
This example uses long data with complex data structure , so pprint() The output is more standardized and easy to read .
Extended reading :
pprint There are other methods for the module as follows , See official documents for details :
pprint.pformat((object,indent=1,width=80, depth=None)
# Returns the formatted object string
pprint.pprint(object,stream=None,indent=1, width=80, depth=None)
# Output the formatted object string to the specified stream, End with a line break
pprint.isreadable(object)
# Judge the object object Whether the string object of is readable
pprint.isrecursive(object)
# Determine whether an object needs recursive representation
pprint.saferepr(object)
# Returns an object string , If the child object in the object is recursive , It's all replaced by . This form
————————————————
Copyright notice : This paper is about CSDN Blogger 「 Relying on the sword, Tianke 」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/menghuanshen/article/details/104236369