Thank you Alan, Steven, I don't care about the characters from the pickle operation per se, I just want the list to be stored in its native format.
What I am trying to do is basically the Unix shell equivalent of: "Unix command" > newfile.txt I am trying to store the list that I get from my code in a separate file, in human-readable format. On Mon, Feb 4, 2013 at 1:03 AM, Alan Gauld <alan.ga...@btinternet.com>wrote: > On 03/02/13 19:26, Spyros Charonis wrote: > >> I am experiencing a strange result with the pickle module when using it >> to write certain results to a separate file. >> > > The only strangec results using pickle would be if the uinpickle failed to > bring back that which was pickled. > Pickle is a storage format not a display format. > > > In short, I have a program that reads a file, finds lines which satisfy >> some criteria, and extracts those lines, storing them in a list. >> > > Extracting them with pickle I hope? That's the only thing that should be > used to unpickle a pickled file. > > > The list of extracted lines looks like this: >> >> ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 >> N >> >> The output stored from the call to the pickle.dump method, however, >> looks like this: >> >> (lp0 >> S'ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 >> N \r\n' >> > > Yep, I'm sure pickle can make sense of it. > > > Does anyone know why the strings lp0, S', aS' are showing up? >> > > Because that's what pickle puts in there to help it unpickle it later. > > Why do you care? You shouldn't be looking at it (unless you want to > understand how pickle works). > > pickle, as the name suggests, is intended for storing python objects > for later use. This is often called object persistence in programming > parlance. It is not designed for anything else. > > If you want cleanly formatted data in a file that you can read in a text > editor or similar you need to do the formatting yourself or use another > recognised format such as CSV or configparser (aka ini file). > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > ______________________________**_________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor