python-本地读取和保存字典文件

版权声明:知识无界限,大家可自由转载。 https://blog.csdn.net/xidianbaby/article/details/86537871
dic = {'a': 1, 'b': 2, 'c': 3, 'd': 1}

# save to local
f = open("..\\data\\dict.txt", 'w')
f.write(str(dic))
f.close()
print("save dict successfully.")

# read from local
f = open("..\\data\\dict.txt", 'r')
dict_ = eval(f.read())
f.close()
print("read from local : ", dict_)

猜你喜欢

转载自blog.csdn.net/xidianbaby/article/details/86537871
今日推荐