I have a python dictionary in a file in a format like this:
(dp0 S'Test' p1 S'Test1' p2 sS'Test2' p3 S'Test2' p4 sS'Starspy' p5 S'SHSN4N' p6 s.
see: Save a dictionary to a file (alternative to pickle) in Python?
and I want to read it back.
According to the question in the link, this has been created saving it with pickle. But, when I try to save a dictionary with pickle the format that I obtain does not correspond.
For example, the code:
import pickle
mydict = {'a': 1, 'b': 2, 'c': 3}
output = open('myfile.dict', 'wb')
pickle.dump(mydict, output)
output.close()
produces a file with the content
€}q (X aqKX bqKX cqKu.
I can read it back OK, but it has not the format of my file (that correspond to a nested dictionary). So, I have two questions:
First, how can I write a file with the format ... (dp0 S'Test' p1 S'Test1' p2 sS'Test2' p3 S'Test2' p4 sS'Starspy' p5 S'SHSN4N' p6 s. ?
Second, how can I read a file with that format?