On Tue, Feb 24, 2015 at 3:05 PM, <bayk...@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.
-- https://mail.python.org/mailman/listinfo/python-list