[Tutor] pickle.dump yielding awkward output

Spyros Charonis s.charonis at gmail.com
Sun Feb 3 20:26:05 CET 2013


Hello Pythoners,

I am experiencing a strange result with the pickle module when using it to
write certain results to a separate file.

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. I am
trying to write this list to a separate 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

ATOM      2  CA  GLN A   1      29.809  11.972  54.274  1.00 58.51
  C

ATOM      3  C   GLN A   1      28.376  11.536  54.029  1.00 55.13
  C

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'
p1
aS'ATOM      2  CA  GLN A   1      29.809  11.972  54.274  1.00 58.51
    C  \r\n'
p2
aS'ATOM      3  C   GLN A   1      28.376  11.536  54.029  1.00 55.13
    C  \r\n'

The code I am using to write the output to an external file goes as follows:

def export_antibody_chains():
''' EXPORT LIST OF EXTRACTED CHAINS TO FILE '''
chains_file = open(query + '_Chains', 'wb')
pickle.dump(ab_chains, chains_file)  # ab_chains is global
chains_file.close()
return

Does anyone know why the strings lp0, S', aS' are showing up?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130203/8f1bb8af/attachment-0001.html>


More information about the Tutor mailing list