Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.046 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'removes': 0.07; 'subject:bug': 0.07; 'get.': 0.09; 'prefix': 0.09; '24,': 0.16; 'backslash': 0.16; 'does,': 0.16; 'guessing': 0.16; 'such,': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'feb': 0.22; '>>>': 0.22; 'email addr:gmail.com>': 0.22; 'to:name:python-list@python.org': 0.22; 'error': 0.23; '>>>': 0.24; 'case.': 0.24; '(see': 0.26; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'characters': 0.30; 'specified': 0.30; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "skip:' 10": 0.31; 'quite': 0.32; 'url:python': 0.33; 'received:74.125.82': 0.34; 'could': 0.34; 'except': 0.35; 'skip:u 20': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'list': 0.37; 'skip:& 10': 0.38; 'url:library': 0.38; 'handle': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'expect': 0.39; 'received:74.125': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'remove': 0.60; 'skip:u 10': 0.60; 'url:3': 0.61; 'first': 0.61; 'forward': 0.65; 'believe': 0.68; 'url:4': 0.69; 'manner': 0.72; "'if": 0.84; '2015': 0.84; 'code):': 0.84 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=JFlUc7qWObOGVf3hmu2bc8ugW0G4wRB56rKepkt6res=; b=IqcMiJdfwOnTULa73V8tuSV27Ng+aQaqt291b14SZonVPuYp2kJmZPjT7qJpbiq7/n uN+sMbcG2VIwu8OAw1MgM0R2HXo77jTXSCsp3l3afGA9Gn+i8KtZHXbrdiqjCj2VODpK izjjRTqTNPJrBbhrzTbEbFZcL3TJQHJ5/8h46mYCHVSrXR6+dujSROlHpcLFcVUr14Fo DMjC5IgX0f4+uSOJLafZMSrPP7U9f7D94hd77GhhkaPEWed8ApCSFbq2L3+HXeWy65mz QorHeeIz13E1n6eiFRoxfEj3jV4Iw2BbLpZTiqzTBVKqCWvkNkQHzbluJC+ZGE712j5g BSDw== X-Gm-Message-State: ALoCoQnhD+1GBY1Be4GDIpvzkOtP8aMDeCMF//68QRlLZTUQR7Ll+dfTNiRMHRWRubRw7Hgqrrnl X-Received: by 10.195.12.97 with SMTP id ep1mr583176wjd.134.1424820146832; Tue, 24 Feb 2015 15:22:26 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <3a54074b-2517-472b-9fcc-50348933a959@googlegroups.com> References: <3a54074b-2517-472b-9fcc-50348933a959@googlegroups.com> From: Chris Kaynor Date: Tue, 24 Feb 2015 15:22:06 -0800 Subject: Re: strip bug? To: "python-list@python.org" Content-Type: multipart/alternative; boundary=047d7bfceb40b8997e050fddcacf 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: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424820483 news.xs4all.nl 2859 [2001:888:2000:d::a6]:42348 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86358 --047d7bfceb40b8997e050fddcacf Content-Type: text/plain; charset=UTF-8 On Tue, Feb 24, 2015 at 3:05 PM, wrote: > >>> 'http://xthunder'.strip('http://') > 'xthunder' > >>> 'http://thunder'.strip('http://') > 'under' > >>> > > I could understand backslash but forward slash? I believe the issue is that str.strip does not do quite what you are thinking it does, however your message is very unspecific about what you expect to get. It seems that you except str.strip to remove a sub-string, while it actually removes the list of specified characters (see https://docs.python.org/3.4/library/stdtypes.html?highlight=str.strip#str.strip). As such, you would get the same result from 'http://thunder'.strip('htp:/') and 'http://thunder'.strip('/thp:') as from your samples. To get what I am guessing you want ("xthunder" for the first and "thunder" for the second), you should use splicing, likely combined with str.startswith() (untested code): url = 'http://thunder/ if url.startswith('http://'): url = url[7:] else # Handle case without the prefix in whatever manner is correct for your case. Possibly continue, possibly error out. --047d7bfceb40b8997e050fddcacf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On T= ue, Feb 24, 2015 at 3:05 PM, <baykiwi@gmail.com> wrote:
=
>>> 'http://xthunder'.strip('http://')
'xthunder'
>>> 'http://thund= er'.strip('http://')
'under'
>>>

I could understand backslash but forward slash?

=
I believe the issue is that str.strip does not do quite what you are t= hinking it does, however your message is very unspecific about what you exp= ect to get. It seems that you except str.strip to remove a sub-string, whil= e it actually removes the list of specified characters (see https://docs.python.org/3.4/library/stdtypes.html?highlight=3Dstr.strip= #str.strip). As such, you would get the same result from 'http://thunder'.strip('h= tp:/') and 'http://th= under'.strip('/thp:') as from your samples.

<= /div>
To get what I am guessing you want ("xthunder" for the = first and "thunder" for the second), you should use splicing, lik= ely combined with str.startswith() (untested code):
url =3D '= http://thunder/
if url.startswith= ('http://'):
=C2=A0 =C2=A0 url =3D url[7:]
els= e
=C2=A0 =C2=A0 # Handle case without the p= refix in whatever manner is correct for your case. Possibly continue, possi= bly error out.
--047d7bfceb40b8997e050fddcacf--