Hi, On 19 November 2011 19:37, Joe Batt <joeb...@hotmail.co.uk> wrote:
> I am getting the following error in Python 3 > > Traceback (most recent call last): > File "/Users/joebatt/Desktop/python/pickling puzzle 5.py", line 39, in > <module> > a=pickle.load(file) > _pickle.UnpicklingError: unpickling stack underflow > > when I am running the following > > import pickle > file=open('///Users/joebatt/Desktop/banner.p.webarchive','rb') > a=pickle.load(file) > file.close() > print (a) > > OK, there's basically 2 things you can infer from the error message: 1) The unpickling failed (to which you should ask yourself, why?), and 2) The picking/unpickling logic must use some sort of stack internally. The first is the most important bit as far as you're concerned, and the second is for the most part irrelevant from your point of view, since you're not really interested in the inner workings of pickling and unpickling. So why might the unpickling be failing? Broadly speaking, it must be one of 2 things -- either you're doing it wrong, or you're putting the wrong stuff in, so to speak. The first seems unlikely, so it's likely the second. So, I'm with Terry on this one, I'd guess that the input that you're feeding into pickle.load() is not a valid pickle file, probably because pickle files are binary files and you probably opened it as a text file. See here: http://docs.python.org/py3k/library/functions.html#open Cheers, Walter
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor