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 dictionary object when the program is run again.
How would I convert a dictionary object into a string that can be written to a file and loaded back into a dictionary object? This will hopefully support dictionaries containing dictionaries.
Python – Convert a python dict to a string and back
dictionaryjsonpythonserialization
Related Topic
- Python – What are metaclasses in Python
- Python – How to safely create a nested directory in Python
- Java – a serialVersionUID and why should I use it
- Python – Does Python have a ternary conditional operator
- Python – Convert bytes to a string
- Javascript – Convert form data to JavaScript object with jQuery
- Python – Does Python have a string ‘contains’ substring method
- Python – How to remove a key from a Python dictionary
Best Answer
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.