Python 3 resuma a file download

Tim Chase python.list at tim.thechases.com
Wed Jul 1 22:04:19 CEST 2015


On 2015-07-01 21:51, Peter Otten wrote:
> use a loop:
> 
> CHUNKSIZE = 16*1024 # for example
> while True:
>    data =  response.read(CHUNKSIZE)
>    if not data:
>        break
>    out_file.write(data)
> 
> 
> This can be simplified:
> 
> shutil.copyfileobj(response, out_file)

It's these little corners of Python that make me wonder how many
times I've written that `while` loop when I could have just used a
tested function from the stdlib.  Sigh.

-tkc




More information about the Python-list mailing list