how to download a zip or rar file to local machine using python?

James Stroud jstroud at ucla.edu
Wed Mar 8 06:29:35 CET 2006


dongdong wrote:
> I wrote as following:
>   content=urllib2.urlopen("http://www.sdfagfa.org/asasg/a.zip").read()
>   f=open("d:\\a.zip",'a+',1)
>   f.writelines(content)
> 
> the zip file has been download to my machine,but when be unzip , error
> occurs:
> " there is an  error at the end of the file"
> 

f=open("d:\\a.zip",'a+',1)

Here you want to open a.zip as a text file (default) for appending, in 
both read and write mode.

I think sufficient would be

f=open("d:\\a.zip",'wb')

For opening a new file and writing as binary.

Then you will want:

f.write(content)

f.close()

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list