unpickle error

S

sosman

After pickling several lists of objects using protocol 2, when I
unpickle I get:
TypeError: ord() expected a character, but string of length 0 found

When I use protocol 0 (ascii) this doesn't occur.

Now it is almost certainly something I have stuffed up but it is not
obvious to me how to debug this kind of problem.

When I mean pickling several lists, I open a file, call dump for each
list of objects then close the file. Similarly for unpickling.
 
R

Richie Hindle

[sosman]
After pickling several lists of objects using protocol 2, when I
unpickle I get:
TypeError: ord() expected a character, but string of length 0 found

When I use protocol 0 (ascii) this doesn't occur.

On Windows you need to open your files in binary mode using open(name, 'rb')
or open(name, 'wb') when reading and writing non-ASCII data. Could that be
the problem?
 
S

sosman

Richie said:
[sosman]
After pickling several lists of objects using protocol 2, when I
unpickle I get:
TypeError: ord() expected a character, but string of length 0 found

When I use protocol 0 (ascii) this doesn't occur.


On Windows you need to open your files in binary mode using open(name, 'rb')
or open(name, 'wb') when reading and writing non-ASCII data. Could that be
the problem?

Doh. Thank you, that appears to have done the trick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top