Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.054 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'that?': 0.05; 'subject:file': 0.07; 'friday,': 0.09; 'subject:into': 0.09; 'subject:How': 0.10; 'python': 0.11; '"w")': 0.16; '50mb.': 0.16; 'seconds.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; 'written': 0.21; 'header:User-Agent:1': 0.23; 'specify': 0.24; 'url:moin': 0.24; 'least': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'that.': 0.31; 'url:wiki': 0.31; 'file': 0.32; 'linux': 0.33; 'url:python': 0.33; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'seconds': 0.37; 'system,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'most': 0.60; 'numbers': 0.61; 'first': 0.61; 'times': 0.62; 'email addr:gmail.com': 0.63; 'reached': 0.63; 'size.': 0.65; 'received:74.208': 0.68; 'limit': 0.70; 'obvious': 0.74; 'fast,': 0.84; 'received:74.208.4.194': 0.84; '2013': 0.98 Date: Fri, 17 May 2013 07:58:43 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How to write fast into a file in python? References: <87f9a3d4-427e-472f-bee7-9501ba842b36@googlegroups.com> In-Reply-To: <87f9a3d4-427e-472f-bee7-9501ba842b36@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:CuQ9yvgZHEP2NBdQR98YDegTqX/NbyPGrWtNX3MwNHx qYeLIJSwBSY7+yV3oasNpByGvNPCC+pPXjLUtnd5/qTIxHFDOB TqggEd7RxAGJJ3okCTW9UprAkJfRTjinVFY0JJIGyZN7lIIOwo UxJhss8sWZHFSOOikRZ27172ry1mAYpyzRwsLM3U7S5LiWoTbm AcPhB5UxGzzqz3x9gTiO7jVPS6+3IImd95oFgJN3z4SBpnNCk6 NArUCHOXkO5odZE/3DvrEkcxT77E3sCuKgF+8oIhNV+LQ0k2vE H1C27s8akYMJdWqyomacmW0FwXGHBmpveip7VTJvx33XfV+yw= = 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368791935 news.xs4all.nl 15891 [2001:888:2000:d::a6]:40371 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45474 On 05/17/2013 12:35 AM, lokeshkoppaka@gmail.com wrote: > On Friday, May 17, 2013 8:50:26 AM UTC+5:30, lokesh...@gmail.com wrote: >> I need to write numbers into a file upto 50mb and it should be fast >> >> can any one help me how to do that? >> >> i had written the following code.. >> >> >> value = 0 >> >> with open(filename, "w") as f: >> >> while f.tell()< size: >> >> f.write("{0}\n".format(value)) >> If you must use googlegroups, at least read this http://wiki.python.org/moin/GoogleGroupsPython. >> >> >> it takes about 20sec i need 5 to 10 times less than that. > size = 50mb > Most of the time is spent figuring out whether the file has reached its limit size. If you want Python to go fast, just specify the data. On my Linux system, it takes 11 seconds to write the first 6338888 values, which is just under 50mb. If I write the obvious loop, writing that many values takes .25 seconds. -- DaveA