Mark Tolonen schreef:
"Timo" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
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.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to