How do I serialize a Python dictionary into a string, and then back to a dictionary? The dictionary will have lists and other dictionaries inside it.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on what you’re wanting to use it for. If you’re just trying to save it, you should use
pickle(or, if you’re using CPython 2.x,cPickle, which is faster).If you want it to be readable, you could use
json:jsonis, however, very limited in what it will support, whilepicklecan be used for arbitrary objects (if it doesn’t work automatically, the class can define__getstate__to specify precisely how it should be pickled).