[Tutor] Downloading Files from the net

Timo timovwb at gmail.com
Mon Sep 29 09:54:36 CEST 2008

Mark Tolonen schreef:
> "Timo" <timovwb at gmail.com> wrote in message 
> news:48dfb602.2283420a.7dff.2f6f at mx.google.com...
>> What is the best/correct way to download files from a webpage?
>> www.example.com/example.mp3 for instance.
>> I know how to open the site (with urllib), but have no idea how to 
>> write the file to the harddisk.
> Quick and dirty, if example.mp3 isn't too big to fit in memory at once:
> import urllib
> fin = urllib.urlopen('http://www.example.com/example.mp3')
> fout = open('example.mp3','wb')
> fout.write(fin.read())
> fin.close()
> fout.close()
> -Mark

Ok, this is what I found too, tested it and it worked. But this "if 
example.mp3 isn't too big to fit in memory at once" makes me "worry". 
Ofcourse not for a simple mp3, but if it is a much larger file.

More information about the Tutor mailing list