dict保存成文件(对象序列化)

d = dict(name='TSQ', age=18)

import pickle
with open("dict.file", "wb") as f:
    pickle.dump(d, f)

文件读取成dict(文件反序列化)

d = {}

import pickle
with open("dict.file", "rb") as f:
    d = pickle.load(f)

print(d)

print(d)的结果是

{'name': 'TSQ', 'age': 18}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2021-10-11
  • 2021-08-15
  • 2021-06-22
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2021-06-29
  • 2021-10-07
  • 2022-12-23
  • 2021-07-26
  • 2021-08-20
相关资源
相似解决方案