This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pickle example contains errors
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: edgimar, georg.brandl, rhettinger
Priority: normal Keywords:

Created on 2007-04-13 07:22 by edgimar, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg31769 - (view) Author: Mark Edgington (edgimar) Date: 2007-04-13 07:22
In the pickle documentation (see http://docs.python.org/lib/pickle-example.html ), there is an error.  At the end of the page, under the "A sample usage might be..." section, the file for dumping is opened in text-mode instead of binary mode.

This bit me because I was lazy and didn't re-read all of the pickle documentation, but based some code on this snippet.  The problem occurs under certain circumstances when pickling a type 'object' instance (newstyle) under Windows, and then attempting to unpickle it under Linux.  You get the following error: ImportError: No module named copy_reg.  This made no sense to me, and it took a long time to figure out that the problem was due to the mode in which the file was saved (what that has to do with the ImportError I still have no idea...).  If interested, I could attach a test script which is supposed to load the data to a class instance, and two pickle dumps, one which works, and the other which fails.

Perhaps a related suggestion which maybe should be in a different bug is that pickle should check to see when it writing to a filehandle if the filehandle's mode is binary or text, and to issue a warning if it is text.
msg55219 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-08-23 21:25
The example is already fixed; also, a note is in the docs that you must
use binary mode for protocols >= 1.
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44839
2007-08-23 21:25:40georg.brandlsetstatus: open -> closed
resolution: out of date
messages: + msg55219
nosy: + georg.brandl
2007-04-13 07:22:53edgimarcreate