[Tutor] EOF error with pickle?

Clay Shirky clay at shirky.com
Wed Dec 24 07:19:39 EST 2003


I'm trying to use pickle to store some nested lists. The program writes to
the output file fine, but when I read the same file as input, I get an EOF
error.

Here's the test script I wrote to reproduce the error:

import pickle
test_list = range(100)

f = open("pickle.dat", 'w')
pickle.dump(test_list, f)
print "dumped..."           # this works

g = open("pickle.dat")
new_list = pickle.load(g)
print new_list              # this generates the error below

-----

/Users/cshirky/test> test_pickle.py
dumped...
Traceback (most recent call last):
  File "./test_pickle.py", line 17, in ?
    new_list = pickle.load(g)
  File 
"/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/pickle.py",
line 1390, in load
    return Unpickler(file).load()
  File 
"/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/pickle.py",
line 872, in load
    dispatch[key](self)
  File 
"/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/pickle.py",
line 894, in load_eof
    raise EOFError
EOFError




More information about the Tutor mailing list