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


Groups > comp.lang.python > #45517

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <carlosnepomuceno@outlook.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'that?': 0.05; 'convention.': 0.07; 'lines,': 0.07; 'subject:file': 0.07; 'happen.': 0.09; 'mess': 0.09; 'subject:into': 0.09; 'subject:How': 0.10; 'python': 0.11; 'windows': 0.15; '*any*': 0.16; 'newlines': 0.16; 'simplicity,': 0.16; 'subject:python': 0.16; 'files.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'bit': 0.19; 'putting': 0.22; 'python?': 0.22; 'to:name :python-list@python.org': 0.22; 'received:65.55.116': 0.24; 'file.': 0.24; 'header:In-Reply-To:1': 0.27; 'fastest': 0.30; 'code': 0.31; 'that.': 0.31; 'file': 0.32; 'quite': 0.32; 'text': 0.33; 'open': 0.33; 'date:': 0.34; 'editor': 0.35; 'but': 0.35; 'really': 0.36; '+0100': 0.36; 'accessing': 0.36; 'subject:?': 0.36; 'two': 0.37; 'email addr:python.org': 0.37; 'writes': 0.38; 'to:addr:python-list': 0.38; 'track': 0.38; 'skip:_ 30': 0.39; 'subject:': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'length': 0.61; 'mentioned': 0.61; 'email addr:gmail.com': 0.63; 're:': 0.63; 'more': 0.64; 'email name:python-list': 0.65; 'account.': 0.80; 'faster.': 0.84; 'notepad,': 0.84; '2013': 0.98
X-TMN [lK85ywhtH965zVNBtBp7YTfc/7oA6Wy2]
X-Originating-Email [carlosnepomuceno@outlook.com]
From Carlos Nepomuceno <carlosnepomuceno@outlook.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: How to write fast into a file in python?
Date Sat, 18 May 2013 20:00:06 +0300
Importance Normal
In-Reply-To <CAA=1kxRK3F3_gYGEecRkHS33e5nEHa1KQqAK0BeODty0RqJH5A@mail.gmail.com>
References <CAA=1kxRK3F3_gYGEecRkHS33e5nEHa1KQqAK0BeODty0RqJH5A@mail.gmail.com>
Content-Type text/plain; charset="iso-8859-1"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-OriginalArrivalTime 18 May 2013 17:00:06.0743 (UTC) FILETIME=[25D38E70:01CE53E9]
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.1808.1368896475.3114.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368896475 news.xs4all.nl 15930 [2001:888:2000:d::a6]:46017
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45517

Show key headers only | View raw


Python really writes '\n\r' on Windows. Just check the files.

Internal representations only keep '\n' for simplicity, but if you wanna keep track of the file length you have to take that into account. ;)

________________________________
> Date: Sat, 18 May 2013 08:49:55 +0100 
> Subject: RE: How to write fast into a file in python? 
> From: fabiosantosart@gmail.com 
> To: carlosnepomuceno@outlook.com 
> CC: python-list@python.org 
>  
>  
> On 17 May 2013 19:38, "Carlos Nepomuceno"  
> <carlosnepomuceno@outlook.com<mailto:carlosnepomuceno@outlook.com>>  
> wrote: 
> > 
> > Think the following update will make the code more portable: 
> > 
> > x += len(line)+len(os.linesep)-1 
> > 
> > Not sure if it's the fastest way to achieve that. :/ 
> > 
>  
> Putting len(os.linesep)'s value into a local variable will make  
> accessing it quite a bit faster. But why would you want to do that? 
>  
> You mentioned "\n" translating to two lines, but this won't happen.  
> Windows will not mess with what you write to your file. It's just that  
> traditionally windows and windows programs use \r\n instead of just \n.  
> I think it was for compatibility with os/2 or macintosh (I don't  
> remember which), which used \r for newlines. 
>  
> You don't have to follow this convention. If you open a \n-separated  
> file with *any* text editor other than notepad, your newlines will be  
> okay. 		 	   		  

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