Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.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; 'string.': 0.05; 'subject:Python': 0.06; 'data:': 0.09; 'f.close()': 0.09; 'separately': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; '12:50': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterating': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'cc:addr:python.org': 0.22; 'file.': 0.24; 'cc:2**0': 0.24; '15,': 0.26; 'this:': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'fastest': 0.30; 'message-id:@mail.gmail.com': 0.30; 'file': 0.32; 'received:google.com': 0.35; 'data,': 0.36; 'list': 0.37; 'project': 0.37; 'performance': 0.37; 'skip:o 20': 0.38; 'presently': 0.38; 'that,': 0.38; 'anything': 0.39; 'first': 0.61; "'with'": 0.84; 'subject:Fast': 0.84; 'to:none': 0.92; 'tied': 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=T2+24kiH/jOA9602fWKUZMULpyISAQ8S6NUdAxcA/FQ=; b=F/YeYhDliTeBLaE+A5eqYJw17jeURpbXVG+lOZ9kgV8OfJQXqMuiefkQRfvYsnwnFL dWsViRe59IMHu8zE0sBr5JDcOykyVIBmBtO6O9i3iiLfPGRF/BA43tJRK1P1mwMuJ8o/ 0Ij5YUGnf9NGJMEt38JFHuy+bxZeV6f/zMsBiStoUBSA9s51egR6PqokOupjPRj9OF/m tkA1H4IiowDLBfkJeA6WtsbgpT3OYUpSPHAhAl1/FOoYNwi41v94njbHnwcWCsAvVk1S Ysg6wkGdIHBysQmJwbVG3OBagCYgGk3X8pp+QcMXkVR7sVXLAXgW3TDOlgVmJXahyTQy ptmQ== MIME-Version: 1.0 X-Received: by 10.68.183.164 with SMTP id en4mr1779670pbc.169.1389708188947; Tue, 14 Jan 2014 06:03:08 -0800 (PST) In-Reply-To: References: Date: Wed, 15 Jan 2014 01:03:08 +1100 Subject: Re: Python Fast I/o 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.15 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389708197 news.xs4all.nl 2955 [2001:888:2000:d::a6]:36165 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63905 On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia wrote: > I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file. > > Presently I am using this: > > with open('index.txt','w') as f: > f.write("".join(data)) > f.close() with open('index.txt','w') as f: for hunk in data: f.write(hunk) You don't need to f.close() - that's what the 'with' block guarantees. Iterating over data and writing each block separately means you don't have to first build up a 200MB string. After that, your performance is going to be mainly tied to the speed of your disk, not anything that Python can affect. ChrisA