rstrip()

News123 news1234 at free.fr
Sun Jul 18 07:18:10 EDT 2010


Mark Lawrence wrote:
> On 17/07/2010 23:17, MRAB wrote:
>> Chris Rebert wrote:
>>> On Fri, Jul 16, 2010 at 10:27 AM, MRAB <python at mrabarnett.plus.com>
>>> wrote:
>>>> Jason Friedman wrote:
>>>
>>> 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.
>>>
>> Even better, a set (or tuple) of strings. It's the kind of thing that
>> could've been done in Python 3, with Python 2's .strip(string) becoming
>> .strip(set(string)), but it didn't occur to me until too late. :-(
> 
> Maybe 3.2 which is still in alpha, if not 3.3?
> 
> Kindest regards.
> 
> Mark Lawrence.
> 

It could even be introduced without breaking compatibility.

if being defined as
str.rstrip([iterable])
so you could either call
string.rstrip( [ '-dir' ] )
or  as
string.rstrip( '-dir' )


However I wouldn't be sure, that it really reduces the amount of
questions being asked.

In order to reduce the ambiguities one had to have two distinct functions.
If one wouldn't want to break backwards-compatibility, then the new
names would be  for stripping off prefixes / suffixes and could be
str.strip_prefix(prefixes) / str.rstrip_suffix(suffixes)


I'd love to have this functionality, though I can live with importing my
self written function.



More information about the Python-list mailing list