From: Thomas Jollans on
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(a)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.

From: News123 on
Thomas Jollans wrote:

>
>
>> 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.
>
It's silly with the example of '-dir' it's much less silly with
a string like ' \t'.

The doc is rather clear about it:
str.rstrip([chars])

It is marked 'chars' and not 'suffix'

The textual description is even clearer:
"The chars argument is not a suffix; rather, all combinations of its
values are stripped:"


When I asked in this grpup about a way of how to strip off a prefix I
never even considered strip as a solution having read the doc before.

I also think, that the functionality of strip / rstrip is useful as is.


It would just be great to have functions to strip prefixes/suffixes.
If these new commands were alphabetically next to the classic commands,
( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for
string functions would probably use the function, which is appropriate
for his purpose.

Breaking backwardscompatibility within python 3 might not be the best
choice.

>> 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.
>
From: MRAB on
News123 wrote:
> Thomas Jollans wrote:
>
>>
>>> 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.
>>
> It's silly with the example of '-dir' it's much less silly with
> a string like ' \t'.
>
> The doc is rather clear about it:
> str.rstrip([chars])
>
> It is marked 'chars' and not 'suffix'
>
> The textual description is even clearer:
> "The chars argument is not a suffix; rather, all combinations of its
> values are stripped:"
>
>
> When I asked in this grpup about a way of how to strip off a prefix I
> never even considered strip as a solution having read the doc before.
>
> I also think, that the functionality of strip / rstrip is useful as is.
>
>
> It would just be great to have functions to strip prefixes/suffixes.
> If these new commands were alphabetically next to the classic commands,
> ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for
> string functions would probably use the function, which is appropriate
> for his purpose.
>
> Breaking backwardscompatibility within python 3 might not be the best
> choice.
>
[snip]
How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something
similar?
From: News123 on
MRAB wrote:
> News123 wrote:
>> Thomas Jollans wrote:
>>
>>>
>>>> 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.
>>>
>> It's silly with the example of '-dir' it's much less silly with
>> a string like ' \t'.
>>
>> The doc is rather clear about it:
>> str.rstrip([chars])
>>
>> It is marked 'chars' and not 'suffix'
>>
>> The textual description is even clearer:
>> "The chars argument is not a suffix; rather, all combinations of its
>> values are stripped:"
>>
>>
>> When I asked in this grpup about a way of how to strip off a prefix I
>> never even considered strip as a solution having read the doc before.
>>
>> I also think, that the functionality of strip / rstrip is useful as is.
>>
>>
>> It would just be great to have functions to strip prefixes/suffixes.
>> If these new commands were alphabetically next to the classic commands,
>> ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for
>> string functions would probably use the function, which is appropriate
>> for his purpose.
>>
>> Breaking backwardscompatibility within python 3 might not be the best
>> choice.
>>
> [snip]
> How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something
> similar?

sounds reasonable to me
From: Ethan Furman on
MRAB wrote:
> [snip]
> How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something
> similar?

+1 on the names

~Ethan~