Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to download a zip or rar file to local machine using python?

Reply
Thread Tools

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

 
 
dongdong
Guest
Posts: n/a
 
      03-08-2006
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"

 
Reply With Quote
 
 
 
 
James Stroud
Guest
Posts: n/a
 
      03-08-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/
 
Reply With Quote
 
 
 
 
dongdong
Guest
Posts: n/a
 
      03-08-2006
thank james;
and I have got a way to resolve it :
urllib.urlretrieve('http://x.x.x.x/library.zip','library.zip')

 
Reply With Quote
 
dongdong
Guest
Posts: n/a
 
      03-08-2006
but I want to ask: how to find out explaination about the parameters of
'open()' function?

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      03-08-2006
On 7 Mar 2006 22:08:21 -0800, "dongdong" <(E-Mail Removed)>
declaimed the following in comp.lang.python:

> 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...
--
> ================================================== ============ <
> http://www.velocityreviews.com/forums/(E-Mail Removed) | Wulfraed Dennis Lee Bieber KD6MOG <
> (E-Mail Removed) | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

 
Reply With Quote
 
dongdong
Guest
Posts: n/a
 
      03-08-2006
thanks a lot.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: Posting RAR inside ZIP inside RAR Mike Easter Computer Support 0 02-28-2010 05:31 PM
Possibility to add a zip-file to a new zip-file with "add to zip" (right-click) ?? erikkie@casema.nl Computer Support 4 06-26-2006 12:18 AM
*.rar.txt and *rar files jdruk Computer Support 0 10-11-2004 01:21 AM
Auto-opening RAR & ZIP files on download (but not EXE) Daniel Computer Support 3 05-29-2004 12:53 PM



Advertisments