[Tutor] Python riddles

Tim Peters tim.peters at gmail.com
Mon May 9 02:03:00 CEST 2005


[Jacob S.]
> Ok, I'm stuck on #4
>
> I tried using urllib like the source hints... but, when I run my automation
> of the process of typing in the new nothing, I run through about 15 pages,
> then I notice that they add an extra number in the text.
> 60167 or something like that
> This is encouraging. 1) I'm must be getting somewhere--it's not just while 1
> random number generator
> 2) The way they set it up, it looks like they expected me to make the
> mistake that i made to mislead me to a wrong side link. 3) This means that I
> must be doing the right thing.
> Unfortunately, after about 50 pages or so, it stops, apparently using too
> much memory, or something causing the computer to lock badly enough I
> have to wait for 5 minutes for the keyboard interupt to work.  I believe it also
> hints in the source that I should do this about 300 times?  I just want to
> know if I'm on the right track, and maybe a slight push in a better, less
> memory consuming direction...

Just a guess, but if you use urllib.urlopen() to open a URL, you
should  call .close() on the file-like object it returns when you're
done using it.  Otherwise you consume an ever-growing number of
sockets (and other resources) under the covers.

If you follow links more than 300 times, you're definitely doing
something wrong.  Print out everything it's reading to see what you
may be missing then.


More information about the Tutor mailing list