Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to download directly to a file?

Reply
Thread Tools

How to download directly to a file?

 
 
kj
Guest
Posts: n/a
 
      09-04-2009



I want to send a POST request and have the returned content put
directly into a file. Is there a way to do this easily in Python?
I've been looking at the documentation for urllib2, but I can't
see a direct way to do this, other than saving the returned contents
to an in-memory variable and writing out the variable to a file.
But this is precisely what I'd like to avoid.

Thanks!

kynn
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      09-04-2009
kj schrieb:
> I want to send a POST request and have the returned content put
> directly into a file. Is there a way to do this easily in Python?
> I've been looking at the documentation for urllib2, but I can't
> see a direct way to do this, other than saving the returned contents
> to an in-memory variable and writing out the variable to a file.
> But this is precisely what I'd like to avoid.


You get a file-like object, what's wrong reading that chunkwise &
dumping that to a file? Or are 4KB blocksize to hard of a memory constraint?

Diez
 
Reply With Quote
 
 
 
 
kj
Guest
Posts: n/a
 
      09-04-2009
In <> "Diez B. Roggisch" <> writes:

>kj schrieb:
>> I want to send a POST request and have the returned content put
>> directly into a file. Is there a way to do this easily in Python?
>> I've been looking at the documentation for urllib2, but I can't
>> see a direct way to do this, other than saving the returned contents
>> to an in-memory variable and writing out the variable to a file.
>> But this is precisely what I'd like to avoid.


>You get a file-like object, what's wrong reading that chunkwise &
>dumping that to a file? Or are 4KB blocksize to hard of a memory constraint?


Actually, I discovered that urllib.urlretrieve does what I want.
(I'd assumed that urllib2 superseded urllib, but apparently not.)

kynn
 
Reply With Quote
 
Chris Rebert
Guest
Posts: n/a
 
      09-05-2009
On Fri, Sep 4, 2009 at 4:35 PM, kj<> wrote:
> In <> "Diez B. Roggisch" <> writes:
>
>>kj schrieb:
>>> I want to send a POST request and have the returned content put
>>> directly into a file. Â*Is there a way to do this easily in Python?
>>> I've been looking at the documentation for urllib2, but I can't
>>> see a direct way to do this, other than saving the returned contents
>>> to an in-memory variable and writing out the variable to a file.
>>> But this is precisely what I'd like to avoid.

>
>>You get a file-like object, what's wrong reading that chunkwise &
>>dumping that to a file? Or are 4KB blocksize to hard of a memory constraint?

>
> Actually, I discovered that urllib.urlretrieve does what I want.
> (I'd assumed that urllib2 superseded urllib, but apparently not.)


urllib2 is an "advanced" version of the library that gives you more
control over how things are done, but is also more complicated.
Regular urllib is simpler and easier to use, but you don't have as
much control either.
Neither supersedes the other, to my knowledge.

Cheers,
Chris
--
http://blog.rebertia.com
 
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
Direct Download Movies - No Download Limits - Download DivX DVDMovies hussain dandan Python 0 12-06-2009 04:52 AM
Can't download directly from my Mac?? Tom Computer Support 10 01-06-2007 08:02 PM
Using Firewire to download directly from Canon camera? Bill Hilton Digital Photography 6 05-07-2004 07:57 PM
Preview image directly on PC, save directly to HD Patrick M. Digital Photography 3 01-07-2004 08:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57