[Tutor] pickle problem
Joel Goldstick
joel.goldstick at gmail.com
Tue Oct 12 22:32:22 CEST 2010
On Tue, Oct 12, 2010 at 1:35 PM, Roelof Wobben <rwobben at hotmail.com> wrote:
>
>
> Hello,
>
> I have this code :
>
> import urllib
> import pickle
>
> image = urllib.URLopener()
> image.retrieve("http://www.pythonchallenge.com/pc/def/peak.html","banner.p"
> )
> plaatje = open("banner.p", "rb")
> plaatje2 = pickle.load(plaatje)
>
> But it gives this output :
>
> Traceback (most recent call last):
> File "C:\Users\wobben\workspace\oefeningen\src\test2.py", line 7, in
> <module>
> plaatje2 = pickle.load(plaatje)
> File "C:\Python27\lib\pickle.py", line 1378, in load
> return Unpickler(file).load()
> File "C:\Python27\lib\pickle.py", line 858, in load
> dispatch[key](self)
> KeyError: '<'
>
>
> What does this mean ?
>
I have heard of pickle, but never used it. I looked it up in Learning
Python (O'Reilley p 236). The example they give shows that you need to
pickle your object, and put it in a file with pickle(dump(D,F) where D is a
dictionary in the example and F is a file object. You then can retrieve it
with pickle.load(F). The thing you are trying to load is a file that was a
copy of the contents of the url. It is html, and not 'pickled'
I think you are missing a line or two of code from your example tutorial
>
> Roelof
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101012/5311a7e2/attachment-0001.html>
More information about the Tutor
mailing list