Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93387
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Python 3 resuma a file download |
| Date | 2015-07-01 21:51 +0200 |
| Organization | None |
| References | (2 earlier) <ef677bbd-5b40-40b7-8f56-e6a7d39f9ce0@googlegroups.com> <mailman.219.1435763456.3674.python-list@python.org> <4a7fae78-276e-42c6-9d84-1fddbeb99853@googlegroups.com> <mailman.225.1435778925.3674.python-list@python.org> <36d1cf6d-9b99-4d38-8f07-83443bcd2f60@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.226.1435780326.3674.python-list@python.org> (permalink) |
zljubisic@gmail.com wrote:
> But how to read chunks?
Instead of
> data = response.read() # a `bytes` object
> out_file.write(data)
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)
https://docs.python.org/dev/library/shutil.html#shutil.copyfileobj
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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