Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'data:': 0.07; 'subject:file': 0.07; 'python': 0.11; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'stdlib.': 0.16; 'subject:download': 0.16; 'true:': 0.16; 'wrote:': 0.16; "i've": 0.24; 'header:In-Reply-To:1': 0.24; 'written': 0.24; 'example': 0.25; 'wonder': 0.27; 'function': 0.30; 'could': 0.35; 'to:addr :python-list': 0.35; 'skip:o 20': 0.35; 'received:10': 0.37; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'to:addr:python.org': 0.39; 'data': 0.40; 'times': 0.61; 'received:46': 0.63; 'otten': 0.84 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1435781059281:2604403443 X-MC-Ingress-Time: 1435781059280 Date: Wed, 1 Jul 2015 15:04:19 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Python 3 resuma a file download In-Reply-To: References: <9a629cf3-e256-494a-8ff8-3f1f6fc2218c@googlegroups.com> <4a7fae78-276e-42c6-9d84-1fddbeb99853@googlegroups.com> <36d1cf6d-9b99-4d38-8f07-83443bcd2f60@googlegroups.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) Importance: low X-Priority: 4 (Low) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435805143 news.xs4all.nl 2937 [2001:888:2000:d::a6]:55231 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93408 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