[Tutor] Stacks and Stack underflow/Stack overflow
Walter Prins
wprins at gmail.com
Sat Nov 19 21:52:10 CET 2011
Hi,
On 19 November 2011 19:37, Joe Batt <joebatt at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111119/d065c818/attachment.html>
More information about the Tutor
mailing list