Bugs item #1188175, was opened at 2005-04-22 16:02
Message generated for change (Comment added) made by drhok
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1188175&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Heiko Selber (drhok)
Assigned to: Nobody/Anonymous (nobody)
Summary: Pickle with HIGHEST_PROTOCOL "ord() expected..."

Initial Comment:
A Python script that I wrote contains a tree-like data 
structure that cannot be unpickled when pickled with 
protocol==-1 (or 2).

I attached the smallest example I could find.

If run with pickle, the result is:

Traceback (most recent call last):
  File "D:\src\misc\CDROM\python\pickletest.py", line 
68, in ?
    tree=load( f )
  File "C:\Python23\lib\pickle.py", line 1390, in load
    return Unpickler(file).load()
  File "C:\Python23\lib\pickle.py", line 872, in load
    dispatch[key](self)
  File "C:\Python23\lib\pickle.py", line 1189, in 
load_binput
    i = ord(self.read(1))
TypeError: ord() expected a character, but string of 
length 0 found

But with cPickle, the result is:

Traceback (most recent call last):
  File "D:\src\misc\CDROM\python\pickletest.py", line 
68, in ?
    tree=load( f )
EOFError

Small changes in the datastructure lead to different 
results: try changing the line
if level<4:
to
if level<1:

Now cPickle works, but not pickle.

This happens with Python 2.3.3 and 2.3.5 on Windows 
XP.


----------------------------------------------------------------------

>Comment By: Heiko Selber (drhok)
Date: 2005-04-22 20:54

Message:
Logged In: YES 
user_id=865975

Ouch! You're right, I failed to specify binary mode.

Sorry, closing.


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2005-04-22 17:01

Message:
Logged In: YES 
user_id=31435

How did you open the file?  You must open files holding 
pickle data in binary mode on Windows (and should open 
them in binary mode on all platforms).  IOW, you must do

f = open(whatever, 'wb')

when opening a file to which you write a pickle, and must use

f = open(whatever, 'rb')

when opening a file from which you want to read a pickle.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1188175&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to