python.list at tim.thechases.com
Wed Feb 12 23:14:27 CET 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!"
More information about the Python-list