rstrip()

Thomas Jollans thomas at jollans.com
Sun Jul 18 07:42:15 EDT 2010


On 07/18/2010 01:18 PM, News123 wrote:
> 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' )

The former should certainly raise an exception. '-dir' is not a single
character !
Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but
that's just silly.

> 
> 
> 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