Python保存并读取一个字典

2021-01-14 12:14

阅读:726

标签:class   pen   close   保存   output   pytho   cti   资料   data   

  参考资料:

  https://kite.com/python/answers/how-to-save-a-dictionary-to-a-file-in-python  

dictionary_data = {"a": 1, "b": 2}

a_file = open("data.pkl", "wb")
pickle.dump(dictionary_data, a_file)
a_file.close()

a_file = open("data.pkl", "rb")
output = pickle.load(a_file)
print(output)
## OUTPUT
## {‘a‘: 1, ‘b‘: 2}
a_file.close()

Python保存并读取一个字典

标签:class   pen   close   保存   output   pytho   cti   资料   data   

原文地址:https://www.cnblogs.com/chester-cs/p/12941517.html


评论


亲,登录后才可以留言!