时间:2021-07-01 10:21:17 帮助过:29人阅读
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']
运行结果是一样的~~
以上就是解析使用pprint模块格式化数据的详细内容,更多请关注Gxl网其它相关文章!