Reputation: 1604
I have a dictionary with a list as a value such as:
numlist = {'Person': ['2342342', '15:05']}
I pickle it.
outfile = open{"log.txt", "wb")
pickle.dump(numlist, outfile)
I unpickle it.
infile = open("log.txt", "rb")
pickle.load(infile)
How do I convert this binary data back to it's original format? (a dictionary with the variable 'name' as the key, and the list with two items(a variable 'number' for the number and 'calltime' for the time) as the value)?
Upvotes: 1
Views: 4488
Reputation: 500427
OK, let's try it:
In [22]: import pickle
In [23]: numlist = {'Person': ['2342342', '15:05']}
In [24]: outfile = open("log.txt", "wb")
In [25]: pickle.dump(numlist, outfile)
In [26]: outfile.close()
In [27]: infile = open("log.txt", "rb")
In [28]: pickle.load(infile)
Out[28]: {'Person': ['2342342', '15:05']}
As you can see, I got back exactly what I've started with (numlist
). The only thing that's changed compared to your code is that I close outfile
before re-opening it, to make sure that the buffers get flushed.
Upvotes: 2