Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!news2.euro.net!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.002 X-Spam-Evidence: '*H*': 1.00; '*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; 'cc:addr:python-list': 0.11; 'windows': 0.15; '*any*': 0.16; 'newlines': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'bit': 0.19; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'file.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'fastest': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'that.': 0.31; 'file': 0.32; 'quite': 0.32; 'text': 0.33; 'open': 0.33; 'editor': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'accessing': 0.36; 'subject:?': 0.36; 'two': 0.37; 'skip:& 10': 0.38; 'sure': 0.39; 'mentioned': 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'faster.': 0.84; 'notepad,': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=0up5zloxRlUh7sgzMghJbSwZ0su8pwNLU54uzHDm0v8=; b=WgnERbSXvb/+t07KRcHxkMdJp79H6iWMsl+rk6ce7SjysMPEnJoToM3jAX6isFTF7j //XmGaeAhVf5UYrb9uqVBm4TLOl8VHHxYvo8uu6+r10wVntAhyENXmieiw31BlBky03e 5Hx4h6e9WNHc9yjZFyIjATR2FKRNPZP0HuyBsYMTuDqSVcdF+5dyKW3045JU57qxZYo+ dhDC4SQ+p4vLxiR3VxbCmoGCVxCcuRlEiD6VxHjB/8cY4PyEnS7ro3CchskJpV2Ec/Wr oPO96L4ixiv/t4Z0rlimMUc3gl8XcT2THUQIN2ha83PeTR8plVMhSrOHC0568kn+K0bB ZIFw== MIME-Version: 1.0 X-Received: by 10.224.205.8 with SMTP id fo8mr39302058qab.62.1368863395144; Sat, 18 May 2013 00:49:55 -0700 (PDT) In-Reply-To: References: <87f9a3d4-427e-472f-bee7-9501ba842b36@googlegroups.com> <51961B73.2070401@davea.name> <51966d15$0$29997$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 18 May 2013 08:49:55 +0100 Subject: RE: How to write fast into a file in python? From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: Carlos Nepomuceno Content-Type: multipart/alternative; boundary=20cf3005dc0a6a04bb04dcf9581d Cc: python-list@python.org 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368863405 news.xs4all.nl 15875 [2001:888:2000:d::a6]:55869 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45497 --20cf3005dc0a6a04bb04dcf9581d Content-Type: text/plain; charset=ISO-8859-1 On 17 May 2013 19:38, "Carlos Nepomuceno" 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. --20cf3005dc0a6a04bb04dcf9581d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On 17 May 2013 19:38, "Carlos Nepomuceno" <carlosnepomuceno@outlook.com> wrote:
>
> Think the following update will make the code more portable:
>
> x +=3D 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 wi= ll make accessing it quite a bit faster. But why would you want to do that?=

You mentioned "\n" translating to two lines, but t= his won't happen. Windows will not mess with what you write to your fil= e. It's just that traditionally windows and windows programs use \r\n i= nstead 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.

--20cf3005dc0a6a04bb04dcf9581d--