Python3-笔记-E-010-库-漂亮打印(这个是谁给翻译的名字吖。。。)pprint

import pprint
#格式化打印
message = 'It was a bright cold day in April, and the clocks were striking thirteen.'
count = {}
for character in message:
count.setdefault(character, 0)
count[character] = count[character] + 1
pprint.pprint(count)

# 格式化写入内容到py文件,然后在加载当作代码使用
import pprint
cats = [{'name': 'Zophie', 'desc': 'chubby'}, {'name': 'Pooka', 'desc': 'fluffy'}]
pprint.pformat(cats)
fileObj = open('myCats.py', 'w')
fileObj.write('cats = ' + pprint.pformat(cats) + '\n')
fileObj.close()
import myCats
print(myCats.cats)

 
posted @ 2017-10-26 13:31  魏桐  阅读(411)  评论(0编辑  收藏  举报