Many times we need to format the data, do you have a headache with data formatting in Python? Pprint will do you a great favor.
The formatting used in the Pprint module can display data in a format that is parsed by the parser and is easy to read. The output is saved in a single line, but you can also use an indent representation when splitting multiple rows of data if necessary.
Import Sysimport Pprintpprint.pprint (Sys.path)
Operation Result:
['',
'/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 ']
You can use Pformat if you just want to get the data, not the output data.
Import Sysimport pprintstr = Pprint.pformat (sys.path) Print str
The output is the same as above