Download parts not whole file in ones

Jordan jordan.taylor2 at gmail.com
Tue Feb 13 12:51:34 EST 2007


On Feb 13, 8:09 am, NOSPAM plz <nos... at riddergarn.dk> wrote:
> Hey,
>
> My problem is, is it possible to download parts of a file while. i think
> is it is called threading
>
> My code thats download the whole webpage, and stunds the app while is is
> downloading:
>
> -----------CODE-----------
> import urllib
> # the heavy file to download
> f = urllib.urlopen("http://da.wikipedia.org/wiki/Wiki")
> # This was supposed to print the file while it downloads
> while 1:
>     print f.read(100)
> -----------/CODE-----------
>
> In my example it just download the whole file, and then print it.
>
> Any suggestions?
>
> Regards
> Andreas

That's because urllib.urlopen() is not a low enough level function to
allow what you want, it will simply open the .  Take a look inside of
urllib.py and maybe you'll find a way to subclass the urllopen()
function to do what you want.

Cheers,
Jordan




More information about the Python-list mailing list