Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45474

Re: How to write fast into a file in python?

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 <davea@davea.name>
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 <davea@davea.name>
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 <e9dcd255-b892-40a0-ae6b-0995a61a270f@googlegroups.com> <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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1784.1368791935.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


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..
>>
>>  <SNIP>
>> value = 0
>>
>> with open(filename, "w") as f:
>>
>> while f.tell()< size:
>>
>> f.write("{0}\n".format(value))
>>   <SNIP more double-spaced nonsense from googlegroups>
   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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to write fast into a file in python? lokeshkoppaka@gmail.com - 2013-05-16 20:20 -0700
  Re: How to write fast into a file in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-17 03:51 +0000
  Re: How to write fast into a file in python? lokeshkoppaka@gmail.com - 2013-05-16 21:35 -0700
    Re: How to write fast into a file in python? Dave Angel <davea@davea.name> - 2013-05-17 07:58 -0400
    RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-17 18:20 +0300
      Re: How to write fast into a file in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-17 16:42 +0000
        RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-17 20:25 +0300
      Re: How to write fast into a file in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-17 17:47 +0000
        RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-17 21:18 +0300
          Re: How to write fast into a file in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-18 04:01 +0000
            Re: How to write fast into a file in python? Chris Angelico <rosuav@gmail.com> - 2013-05-18 15:28 +1000
            Re: How to write fast into a file in python? 88888 Dihedral <dihedral88888@googlemail.com> - 2013-05-18 04:09 -0700
        RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-17 21:33 +0300
        RE: How to write fast into a file in python? Fábio Santos <fabiosantosart@gmail.com> - 2013-05-18 08:49 +0100
        Re: How to write fast into a file in python? Chris Angelico <rosuav@gmail.com> - 2013-05-19 00:29 +1000
        RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-18 20:00 +0300
          Re: How to write fast into a file in python? Tim Roberts <timr@probo.com> - 2013-05-19 19:04 -0700
        Re: How to write fast into a file in python? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-18 15:14 -0400
          Re: How to write fast into a file in python? Roy Smith <roy@panix.com> - 2013-05-18 15:37 -0400
          Re: How to write fast into a file in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-18 22:23 +0000
        Re: How to write fast into a file in python? Fábio Santos <fabiosantosart@gmail.com> - 2013-05-18 22:19 +0100
        Re: How to write fast into a file in python? Dave Angel <davea@davea.name> - 2013-05-18 22:41 -0400
        RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-19 06:53 +0300
        Re: How to write fast into a file in python? MRAB <python@mrabarnett.plus.com> - 2013-05-19 16:44 +0100
        RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-20 13:34 +0300
    Re: How to write fast into a file in python? Dan Stromberg <drsalists@gmail.com> - 2013-05-18 12:38 -0700
    RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-19 08:31 +0300
    RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-19 08:42 +0300
    Re: How to write fast into a file in python? Chris Angelico <rosuav@gmail.com> - 2013-05-19 19:21 +1000
    RE: How to write fast into a file in python? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-19 12:41 +0300

csiph-web