把字典保存在文件中

室友之前给的代码会出错,说整数不能迭代??不知道什么意思,找了个百度回答,解决了编码问题,还解决了字符和数值不能连接的问题(数值化成字符),但是最后是把字典和字典的值打印出来了,不是保存起来了

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import os
write_file = os.getcwd() + '\dit.txt'
print write_file
output = open(write_file,'w')
for i in dict:
print i,bytes(dict[i])
write_str = str(i) + ' ' + bytes(dict[i]) + '\n'
output.write(write_str)
output.close()

啊,这个人是直接保存了一个文件

最后会显示文件路径,

右侧也能看到

https://jingyan.baidu.com/article/f54ae2fcd9a2b91e93b84946.html

把带空格的txt导入excel,不要直接复制粘贴,要从数据-导入外部数据中导入,以空格为分隔符

 

 

 

 


posted @ 2018-10-26 19:40  haolemao  阅读(2283)  评论(0编辑  收藏  举报