[Tutor] pickle.dump yielding awkward output
steve at pearwood.info
Mon Feb 4 01:17:13 CET 2013
On 04/02/13 06:26, Spyros Charonis wrote:
> The output stored from the call to the pickle.dump method, however, looks
> like this:
> Does anyone know why the strings lp0, S', aS' are showing up?
Why do you care?
Pickle is not a human-readable format. It may use plain text (optionally, there are also binary pickle formats) but it is not intended for humans to read or write. Pickle will write whatever information it needs in order to be able to reconstruct the data that you give it. My guess is that the things you see tell pickle which protocol is being used, and that the data you are writing is a list of strings.
Unless you are creating a tool for analyzing pickle files, all you need care is that you can round-trip data into and out of pickle files.
f = open('filename', 'wb')
f = open('filename', 'rb')
newdata = pickle.load(f)
assert data == newdata
If you're looking for a storage format that is human-editable, check out the json or plist modules, or the third-party pyyaml module.
More information about the Tutor