[Tutor] To Specify a directory path to download

Monika Jisswel monjissvel at googlemail.com
Thu Jul 31 19:23:33 CEST 2008


>
> urllib.urlretrieve(url.strip(),save_to)
>
could be changed into this :
folder = '/home/html-data/'
urllib.urlretrieve(url.strip(),folder+save_to)



2008/7/31 swati jarial <swati.jarial at gmail.com>

> Hello,
>
> I am new to python this is the code I have written to download a file from
> the internet and then send en email if any error occurs during download. I
> just want know how to specify which folder to download my files. It
> automatically downloads file to the directory where TEST1.txt sits...
>
> import urllib
> import traceback
> import sys
> import cStringIO
> import ncbi_SendEmail
> import os.path
> import os
>
> try:
>
>     for url in open("test1.txt"):
>         save_to = os.path.basename(url.strip())
>         urllib.urlretrieve(url.strip(),save_to)
>
> except:
>     mssg = cStringIO.StringIO()
>     traceback.print_exc(file=mssg)
>     ncbi_SendEmail.email(mssg.getvalue());
>     mssg.close()
>
>
>
> Thanks a Ton!
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080731/346303ef/attachment-0001.htm>


More information about the Tutor mailing list