利用pprint模块名目化数据
Python的pprint模块中利用的名目化可以凭据一种名目正确的显示数据, 这种名目即可被理会器理会, 又很易读. 输出生存在一个单行内, 但假如有须要, 在支解多行数据时也可利用缩进暗示.
import sys import pprint pprint.pprint(sys.path)
运行功效:
['', '/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']
假如仅仅想得到数据而不是输出数据也可以用pformat
import sys import pprint str = pprint.pformat(sys.path) print str
运行功效:
['', '/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']
运行功效是一样的~~