Am 12.10.2010 19:35, schrieb Roelof Wobben:
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: '<'
The last error indicates that a python module (pickle.py) tried to
access a dictionary (dispatch) with the key "<". The expected value
seems to be a callable as indicated by the (self). But there's no key
"<" in it. So, probably, this module was called with improper data.
If you follow up your stack trace to where the error in your code
occurs, you'll see that something is wrong with "unpickling" the data in
your plaatje file.
Obviously, the data could be passed to the pickle module. So no read
error on the file. What's left? There's probably an issue with the data
in the file.
Now, you have to know that pickling reads and writes Python objects in a
certain format. That means you can only load data with pickling, which
was created by pickling.
Question: Is your data in "banner.p" properly formatted pickling data?
Note: There're different formats for pickling. Check the docs or a very
nice source for examples of the Python Standard lib: PyMOTW (Google
first hit); there's an article about pickling among others. But first
should be the standard documentation.
What does this mean ?
Roelof
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor