In many cases, we need to format the data. do you have a headache in formatting python data? Pprint will help you a lot with the formatting that is used in the pprint module. we often need to format the data. do you have a headache for formatting the data in python? Pprint will help you a lot
The format used in the pprint module can display data in a correct format, which can be parsed by the parser and easy to read. the output is stored in a single row. if necessary, you can use indentation to separate multiple rows of data.
import sysimport pprintpprint.pprint(sys.path)
Running 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']
If you only want to obtain data rather than output data, you can also use pformat
import sysimport pprintstr = pprint.pformat(sys.path)print str
The output result is the same as the preceding one.