Python 3 resuma a file download
Chris Angelico
rosuav at gmail.com
Wed Jul 1 15:28:36 EDT 2015
On Thu, Jul 2, 2015 at 5:24 AM, <zljubisic at gmail.com> wrote:
> with urllib.request.urlopen(req) as response, open(lfile, 'ab') as out_file:
> data = response.read() # a `bytes` object
> out_file.write(data)
>
If a file is big enough to want to resume the download once, you
almost certainly want to be able to resume it a second time. I would
recommend not attempting to do the entire read and write as a single
operation - read chunks and write them to the disk. This will attempt
to read the entire response into a gigantic in-memory bytestring, and
only then start writing.
ChrisA
More information about the Python-list
mailing list