Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86358

Re: strip bug?

References <3a54074b-2517-472b-9fcc-50348933a959@googlegroups.com>
From Chris Kaynor <ckaynor@zindagigames.com>
Date 2015-02-24 15:22 -0800
Subject Re: strip bug?
Newsgroups comp.lang.python
Message-ID <mailman.19155.1424820483.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Feb 24, 2015 at 3:05 PM, <baykiwi@gmail.com> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

strip bug? baykiwi@gmail.com - 2015-02-24 15:05 -0800
  Re: strip bug? Eduardo <xcesar@gmail.com> - 2015-02-24 15:15 -0800
  Re: strip bug? Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-24 16:16 -0700
  Re: strip bug? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-02-25 00:19 +0100
  Re: strip bug? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2015-02-25 00:25 +0100
  Re: strip bug? Chris Kaynor <ckaynor@zindagigames.com> - 2015-02-24 15:22 -0800
  Re: strip bug? Rustom Mody <rustompmody@gmail.com> - 2015-02-25 03:03 -0800
  Re: strip bug? babyG <bintadoma20@yahoo.com> - 2015-02-27 04:18 -0600

csiph-web