rstrip()

Chris Rebert clp2 at rebertia.com
Sat Jul 17 18:11:18 EDT 2010


On Fri, Jul 16, 2010 at 10:27 AM, MRAB <python at mrabarnett.plus.com> wrote:
> Jason Friedman wrote:
>>
>> $ python
>> Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
>> [GCC 4.4.1] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>>
>>>>> "x.vsd-dir".rstrip("-dir")
>>
>> 'x.vs'
>>
>> I expected 'x.vsd' as a return value.
>
> .strip, .lstrip and .rstrip treat their argument like a set of
> characters and remove any of those characters from the end(s) of the
> string.

It's a pity that str.strip() doesn't actually take a set() of length-1
strings, which would make its behavior more obvious and cut down on
this perennial question.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list