Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2a.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'encoded': 0.07; 'f.close()': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"y")': 0.16; "'rb')": 0.16; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'subject:Unicode': 0.16; 'yup,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'tend': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'file': 0.32; 'cases': 0.33; 'checking': 0.33; 'there': 0.35; 'impression': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'files': 0.38; 'skip:p 20': 0.39; 'removing': 0.60; 'worry': 0.60; 'took': 0.61; 'now:': 0.74; 'received:50.22': 0.84; 'subject:you': 0.87 Date: Fri, 6 Jun 2014 05:37:05 -0500 From: Tim Chase To: Johannes Bauer Subject: Re: Unicode and Python - how often do you index strings? In-Reply-To: References: <7xr433z0g3.fsf@ruckus.brouhaha.com> <7xioof9li6.fsf@ruckus.brouhaha.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402051070 news.xs4all.nl 2933 [2001:888:2000:d::a6]:36985 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72829 On 2014-06-06 10:47, Johannes Bauer wrote: > > Personally I tend toward rstrip('\r\n') so that I don't have to > > worry about files with alternative line terminators. > > Hm, I was under the impression that Python already took care of > removing the \r at a line ending. Checking that right now: > > (DOS encoded file "y") > >>> for line in open("y", "r"): print(line.encode("utf-8")) > ... > b'foo\n' > b'bar\n' > b'moo\n' > b'koo\n' > > Yup, the \r was removed automatically. Are there cases when it > isn't? It's possible if the file is opened as binary: >>> f = file('delme.txt', 'wb') >>> f.write('hello\r\nworld\r\n') >>> f.close() >>> f = file('delme.txt', 'rb') >>> for row in f: print repr(row) ... 'hello\r\n' 'world\r\n' >>> f.close() -tkc