Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93385

Re: Python 3 resuma a file download

References <9a629cf3-e256-494a-8ff8-3f1f6fc2218c@googlegroups.com> <mailman.204.1435707788.3674.python-list@python.org> <ef677bbd-5b40-40b7-8f56-e6a7d39f9ce0@googlegroups.com> <mailman.219.1435763456.3674.python-list@python.org> <4a7fae78-276e-42c6-9d84-1fddbeb99853@googlegroups.com>
Date 2015-07-02 05:28 +1000
Subject Re: Python 3 resuma a file download
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.225.1435778925.3674.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jul 2, 2015 at 5:24 AM,  <zljubisic@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python 3 resuma a file download zljubisic@gmail.com - 2015-06-30 08:34 -0700
  Re: Python 3 resuma a file download Cameron Simpson <cs@zip.com.au> - 2015-07-01 09:21 +1000
    Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-01 07:18 -0700
      Re: Python 3 resuma a file download Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-01 09:10 -0600
        Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-01 12:24 -0700
          Re: Python 3 resuma a file download Chris Angelico <rosuav@gmail.com> - 2015-07-02 05:28 +1000
            Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-01 12:31 -0700
              Re: Python 3 resuma a file download Peter Otten <__peter__@web.de> - 2015-07-01 21:51 +0200
              Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-01 12:59 -0700
                Re: Python 3 resuma a file download Peter Otten <__peter__@web.de> - 2015-07-01 22:06 +0200
              Re: Python 3 resuma a file download Tim Chase <python.list@tim.thechases.com> - 2015-07-01 15:04 -0500
                Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-02 13:27 -0700
                Re: Python 3 resuma a file download Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-07-02 23:31 +0200
                Re: Python 3 resuma a file download MRAB <python@mrabarnett.plus.com> - 2015-07-02 23:07 +0100
                Re: Python 3 resuma a file download zljubisic@gmail.com - 2015-07-04 22:31 -0700

csiph-web