How to download directly to a file?

kj no.email at please.post
Sat Sep 5 01:35:04 CEST 2009


In <7gdgslF2ogf8rU1 at mid.uni-berlin.de> "Diez B. Roggisch" <deets at nospam.web.de> 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



More information about the Python-list mailing list