[Tutor] pickle problem

Walter Prins wprins at gmail.com
Wed Oct 13 01:05:52 CEST 2010


On 12 October 2010 18:35, Roelof Wobben <rwobben at hotmail.com> wrote:

> image = urllib.URLopener()
> image.retrieve("http://www.pythonchallenge.com/pc/def/peak.html","banner.p"
> )
>

OK firstly, image is an URLopener, so whatever URL you specify, that's the
file that it will download.  (I would therefore suggest you give it a
slightly better name next time -- you're after all not even going to be
downloading an image so the name "image" is arguably just confusing.)

Now, back to the problem.  Look closely, what file are you downloading?
Right, you're downloading "http://www.pythonchallenge.com/pc/def/peak.html"

However... that's the HTML page itself!  So, what you're doing is to
download the "peak.html" HTML file from the site, and save it locally as
"banner.p"...

But... what you really want is the "banner.p" file *on the website*.  (As
alluded to in the page source, if you view the web page above in your
browser...)

So..., you need to construct the URL to the "banner.p" pickle file on the
website and then retrieve it.  (Hint: Just replace peak.html with banner.p
in the page URL)   You don't even have to do this with Python, you can fetch
the pickle file by hand with your browser first if you want, just punch the
URL into your browser and watch it download the banner.p file. (But, it's
fun to do it in Python! <grin>)

Apologies if I've given away too much!

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101013/a403c46b/attachment.html>


More information about the Tutor mailing list