Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (47.6k points)

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.

1 Answer

0 votes
by (106k points)

To convert a python dict to a string and back 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)

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 10, 2019 in Python by Sammy (47.6k points)

Browse Categories

...