[Tutor] Re: EOF error with pickle?

Lee Harr missive at hotmail.com
Wed Dec 24 08:48:51 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


You need to close the file and reopen it.

Otherwise, I think the file pointer is still pointing to the end of the 
file.

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus




More information about the Tutor mailing list