EOF Error in Python -


evening all,

i've been making programme in python more or less there final piece causing eof error , i'm confused why or how fix it!

myfile =open("positionfile.dat", "rb") #opens , reads file allow data added positionlist = pickle.load(myfile) #takes data file , saves positionlist individualwordslist = pickle.load(myfile) #takes data file , saves individualwordslist myfile.close() #closes file 

with bunch of code before it.

the error is:

traceback (most recent call last): file "p:/a453 scenario 1 +  task 3.py", line 63, in <module>    individualwordslist = pickle.load(myfile) #takes data file , saves individualwordslist eoferror 

any appreciated!

you're calling pickle.load() 2 times on same file. first call read whole file, leaving file pointer @ end of file, hence eoferror. need reset file pointer @ beginning of file using file.seek(0) before second call.

>> import pickle >>> wot = range(5) >>> open("pick.bin", "w") f: ...     pickle.dump(wot, f) ...  >>> f = open("pick.bin", "rb") >>> pickle.load(f) [0, 1, 2, 3, 4] >>> pickle.load(f) traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "/usr/lib/python2.7/pickle.py", line 1378, in load     return unpickler(file).load()   file "/usr/lib/python2.7/pickle.py", line 858, in load     dispatch[key](self)   file "/usr/lib/python2.7/pickle.py", line 880, in load_eof     raise eoferror eoferror >>> f.seek(0) >>> pickle.load(f) [0, 1, 2, 3, 4] >>>  

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -