Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; 'f.close()': 0.09; 'noted,': 0.09; "'w')": 0.16; '-tkc': 0.16; 'dump': 0.16; 'file-like': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'iterable': 0.16; 'wrote:': 0.18; 'handles': 0.22; 'file.': 0.24; 'this:': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'fastest': 0.30; 'file': 0.32; 'trouble': 0.34; 'objects': 0.35; 'data,': 0.36; 'method': 0.36; 'charset:us- ascii': 0.36; 'should': 0.36; 'list': 0.37; 'project': 0.37; 'skip:o 20': 0.38; 'presently': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'most': 0.60; 'save': 0.62; 'received:50.22': 0.84; 'subject:Fast': 0.84 Date: Tue, 14 Jan 2014 08:18:33 -0600 From: Tim Chase To: python-list@python.org Subject: Re: Python Fast I/o In-Reply-To: References: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389712154 news.xs4all.nl 2950 [2001:888:2000:d::a6]:59721 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63911 On 2014-01-14 05:50, 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() > > where data is a list of strings which I want to dump into the > index.txt file -- Most file-like objects should support a writelines() method which takes an iterable and should save you the trouble of joining all the content (and as Chris noted, you don't need the .close() since the with handles it) so the whole thing would condense to: with open('index.txt', 'w') as f: f.writelines(data) -tkc