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

D

dongdong

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"
 
J

James Stroud

dongdong said:
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/
 
D

dongdong

but I want to ask: how to find out explaination about the parameters of
'open()' function?
 
D

Dennis Lee Bieber

but I want to ask: how to find out explaination about the parameters of
'open()' function?

Uhm... Read the Python Library documentation?

Or type "help(open)" at a Python interpreter console prompt...
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top