Convert a python dict to a string and back

后端 未结 10 1648
清酒与你
清酒与你 2020-11-27 10:17

I am writing a program that stores data in a dictionary object, but this data needs to be saved at some point during the program execution and loaded back into the dictionar

10条回答
  •  清歌不尽
    2020-11-27 11:12

    The json module is a good solution here. It has the advantages over pickle that it only produces plain text output, and is cross-platform and cross-version.

    import json
    json.dumps(dict)
    

提交回复
热议问题