Many times we need to format data. Have you ever had a headache with data formatting in python? pprint will help you a lot
The formatting used in the pprint module can correctly display the 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, indentation can also be used when splitting multiple lines of data.
import sys import pprint pprint.pprint(sys.path)
Running results:
['',
'/usr/local/lib/python2.7/ site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/site-packages/web.py-0.36-py2.7.egg ',
'/usr/local/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7 /site-packages/thrift-0.8.0-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/site-packages/setuptools-0.9.8-py2.7. egg',
'/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',
'/usr/local/lib/python2.7/site-packages/PIL']
If you just want to get data instead of outputting data, you can also use pformat
import sys import pprint str = pprint.pformat(sys.path) print str
The output result is the same as above