1. Background
See here mentioned the Pprint.
Going to try.
2.pprint Introduction
Find the online website explanation:
Pprint-data Pretty Printer
It's a good thing to make it easier for you to print some of the relatively complex variables.
3. Use of Pprint
Try to write some code.
Code:
Copy Code code as follows:
#-------------------------------------------------------------------------------
# Name: "Record" Toss Pprint in Python
# Author:crifan Li
#
# created:06/01/2013
# Copyright: (c) Crifan Li 2013
#-------------------------------------------------------------------------------
Import Pprint;
import re;
Def Pprintdemo ():
Varslist = [
[1, 2, 3],
["AB", "C", "Def"],
Re.compile ("\w+"),
("123", "ABC"),
{
"Key1": "Value1",
"Key2": "value2",
},
];
For value in Varslist:
Print value;
Print "-" *80;
pp = Pprint. Prettyprinter (indent=4);
For value in Varslist:
Pp.pprint (value);
print "=" *80;
stuff = [' spam ', ' eggs ', ' lumberjack ', ' knights ', ' ni '];
Stuff.insert (0, stuff[:]);
Print stuff;
Print "-" *80;
Pp.pprint (Stuff)
if __name__ = = ' __main__ ':
Pprintdemo ();
Effect:
Copy Code code as follows:
[1, 2, 3]
[' Ab ', ' C ', ' Def ']
<_sre. Sre_pattern Object at 0x00000000030dd378>
(' 123 ', ' abc ')
{' Key2 ': ' value2 ', ' key1 ': ' value1 '}
--------------------------------------------------------------------------------
[1, 2, 3]
[' Ab ', ' C ', ' Def ']
<_sre. Sre_pattern Object at 0x00000000030dd378>
(' 123 ', ' abc ')
{' Key1 ': ' value1 ', ' key2 ': ' value2 '}
================================================================================
[[' Spam ', ' eggs ', ' lumberjack ', ' knights ', ' ni '], ' spam ', ' eggs ', ' lumberjack ', ' knights ', ' NI ']
--------------------------------------------------------------------------------
[[' Spam ', ' eggs ', ' lumberjack ', ' knights ', ' ni '],
' Spam ',
' Eggs ',
' Lumberjack ',
' Knights ',
' Ni ']
4. Summary
Pprint, it's kind of interesting.
You can use it later in the code debugging process.