The formatting used in Python's pprint module correctly displays data in a format that can be parsed by the parser and is easy to read. The output is saved in a single line, but if necessary, in Indentation can also be used when splitting multi-line data.
import sys import pprint pprint.pprint(sys.path)
Running results:
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
If you just want to obtain data rather than output data, you can also use pformat
import sys import pprint str = pprint.pformat(sys.path) print str
to run Result:
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
The running result is the same~~
The above is the detailed content of Parse formatted data using pprint module. For more information, please follow other related articles on the PHP Chinese website!