Wait... WHAT?

Tim Chase python.list at tim.thechases.com
Wed Feb 12 17:14:27 EST 2014


On 2014-02-12 14:35, Ian Kelly wrote:
> You can't write lists directly to files.  You can only write strings
> to files.  To write and read a list, you'll need to first serialize
> it and later deserialize it. 

To be pedantic, you can only write *bytes* to files, so you need to
serialize your lists (or other objects) to strings and then encode
those to bytes; or skip the string and encode your list/object
directly to bytes.

Though unfortunately, I now have a tweaked version of that late-night
commercial¹:  "PICKLE: SERIALIZE DIRECTLY TO BYTES! PICKLE: SERIALIZE
DIRECTLY TO BYTES! PICKLE: SERIALIZE DIRECTLY TO BYTES!"

-tkc

¹ http://www.youtube.com/watch?v=f_SwD7RveNE




More information about the Python-list mailing list