Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; 'so?': 0.09; 'trailing': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'newline,': 0.16; 'subject:Unicode': 0.16; 'textfile': 0.16; 'truncates': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'paul': 0.24; 'cc:2**0': 0.24; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; "skip:' 10": 0.31; 'that.': 0.31; 'writes:': 0.31; 'fri,': 0.33; 'received:google.com': 0.35; 'ryan': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'how': 0.40; 'removing': 0.60; 'different': 0.65; 'guaranteed': 0.75; 'subject:you': 0.87; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=a5XM5onM9Y72OnzP8brf2ARMtvY4sEobioWsldA98qk=; b=sWWYHsAEOmMRP+MrI/trUop+S7HIaDxe3378pTI5yyPEYirXrZtgkhUM2sjMOS9SWC uec6OXDGieylVAOphm5NdznAUkvSbOpgcTnZY1wqcYXd1Ar+4mmLdVRVEwdSDoc2WkMW 73pLySVXV8/1L27lXngMaVWg+mzXLj5LbReTZBUWdd+/nzRIIS7a1oTEUHu4gUkPY5Gi sItdUpKayTI5+XLg1Wt/UYlWzdroZClm+qWOrm/ziJiW1E2jLN8tlQemT+GhacYpBjDx MqDgg1ENACD9/WWOGrj4NNDqg3ohWTb7zVhHYE6V21/8IJvuhi52pxrpeG8omaG7Hziv TAGA== MIME-Version: 1.0 X-Received: by 10.220.249.6 with SMTP id mi6mr14092491vcb.33.1401998357315; Thu, 05 Jun 2014 12:59:17 -0700 (PDT) In-Reply-To: References: <7xr433z0g3.fsf@ruckus.brouhaha.com> Date: Fri, 6 Jun 2014 05:59:17 +1000 Subject: Re: Unicode and Python - how often do you index strings? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401998360 news.xs4all.nl 2832 [2001:888:2000:d::a6]:39476 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72752 On Fri, Jun 6, 2014 at 4:52 AM, Ryan Hiebert wrote: > 2014-06-05 13:42 GMT-05:00 Johannes Bauer : > >> On 05.06.2014 20:16, Paul Rubin wrote: >> > Johannes Bauer writes: >> >> line = line[:-1] >> >> Which truncates the trailing "\n" of a textfile line. >> > >> > use line.rstrip() for that. >> >> rstrip has different functionality than what I'm doing. > > > How so? I was using line=line[:-1] for removing the trailing newline, and > just replaced it with rstrip('\n'). What are you doing differently? >>> line = "Hello,\nworld!\n\n" >>> line[:-1] 'Hello,\nworld!\n' >>> line.rstrip('\n') 'Hello,\nworld!' If it's guaranteed to end with exactly one newline, then and only then will they be identical. ChrisA