Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.05; 'subject:file': 0.07; 'chunks': 0.09; 'cc:addr:python-list': 0.10; 'thu,': 0.15; 'disk.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'in-memory': 0.16; 'subject:download': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'am,': 0.23; '2015': 0.23; 'header:In- Reply-To:1': 0.24; 'second': 0.24; 'message-id:@mail.gmail.com': 0.28; 'attempting': 0.29; 'once,': 0.29; 'skip:u 20': 0.30; 'certainly': 0.31; 'file': 0.34; 'received:google.com': 0.34; 'attempt': 0.35; 'skip:o 20': 0.35; 'subject:: ': 0.37; 'enough': 0.39; 'data': 0.40; 'entire': 0.61; 'jul': 0.72; 'chrisa': 0.84; 'writing.': 0.84; 'to:none': 0.90; 'response,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Wk5SgGmutUOrShdYy3elH9ZsS7uWd4pZM3NsKg4+AAY=; b=gn/S/j2EsRG1W3Bm651nx8JFPAuvD34+unCEP59RDNdx0Vcao+2sJVmdrP62lGqXzT qodndUvHU/QEGGexrw/ZHmHin8iHHiHJyJIHiZuSTpJgJghy57s5wnfpFRSgwFlWyRDA SLFzu5uen021ZlO2wSmzqOQcoPWO3Q77Q6ACsix+Vj2UAerZCNGEGTHgoEOVdMqd98jw wUBke6bsFG7KtuNR9VM+6ZoPuOCHp+Dqrlvv7o+XO8p3y/SXnrKSFfYRlPF8qE3sqrD/ jStdEB91swptwjXue5JegCb0YFFvAiTe6L5lWNPEbnUE6gqZspEm/vrG8JzKiQlBIddM GYvQ== MIME-Version: 1.0 X-Received: by 10.50.176.194 with SMTP id ck2mr7984209igc.2.1435778916823; Wed, 01 Jul 2015 12:28:36 -0700 (PDT) In-Reply-To: <4a7fae78-276e-42c6-9d84-1fddbeb99853@googlegroups.com> References: <9a629cf3-e256-494a-8ff8-3f1f6fc2218c@googlegroups.com> <4a7fae78-276e-42c6-9d84-1fddbeb99853@googlegroups.com> Date: Thu, 2 Jul 2015 05:28:36 +1000 Subject: Re: Python 3 resuma a file download From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435778925 news.xs4all.nl 2880 [2001:888:2000:d::a6]:33100 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93385 On Thu, Jul 2, 2015 at 5:24 AM, 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