美文网首页
python保存字典和读取字典

python保存字典和读取字典

作者: KK_f2d5 | 来源:发表于2019-02-27 13:42 被阅读0次

读取一个已经保存了的字典

f = open('dict_th','r')
a = f.read()
dict_hi = eval(a)
f.close()

保存一个字典

dict = {}
list1 = []
list2 = []
for line in lines:
    line = line.strip()
    if ">" in line:
        list1.append(line)
    else:
        list2.append(line)
for i in range():
    dict[list1[i]] = list2[i]
f6 = open("dict_th",'w')
f6.write(str(dict))
f6.close()

相关文章

网友评论

      本文标题:python保存字典和读取字典

      本文链接:https://www.haomeiwen.com/subject/ygaxuqtx.html