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: 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 To: "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: References: , <87f9a3d4-427e-472f-bee7-9501ba842b36@googlegroups.com>, <51961B73.2070401@davea.name>, , <51966d15$0$29997$c3e8da3$5496439d@news.astraweb.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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 Python really writes '\n\r' on Windows. Just check the files.=0A= =0A= Internal representations only keep '\n' for simplicity=2C but if you wanna = keep track of the file length you have to take that into account. =3B)=0A= =0A= ________________________________=0A= > Date: Sat=2C 18 May 2013 08:49:55 +0100 =0A= > Subject: RE: How to write fast into a file in python? =0A= > From: fabiosantosart@gmail.com =0A= > To: carlosnepomuceno@outlook.com =0A= > CC: python-list@python.org =0A= > =0A= > =0A= > On 17 May 2013 19:38=2C "Carlos Nepomuceno" =0A= > > =0A= > wrote: =0A= > > =0A= > > Think the following update will make the code more portable: =0A= > > =0A= > > x +=3D len(line)+len(os.linesep)-1 =0A= > > =0A= > > Not sure if it's the fastest way to achieve that. :/ =0A= > > =0A= > =0A= > Putting len(os.linesep)'s value into a local variable will make =0A= > accessing it quite a bit faster. But why would you want to do that? =0A= > =0A= > You mentioned "\n" translating to two lines=2C but this won't happen. = =0A= > Windows will not mess with what you write to your file. It's just that = =0A= > traditionally windows and windows programs use \r\n instead of just \n. = =0A= > I think it was for compatibility with os/2 or macintosh (I don't =0A= > remember which)=2C which used \r for newlines. =0A= > =0A= > You don't have to follow this convention. If you open a \n-separated =0A= > file with *any* text editor other than notepad=2C your newlines will be = =0A= > okay. =