<div dir="auto"><div>The only reason I would support the idea would be to allow multiple suffixes (or prefixes). Otherwise, it just does too little for a new method. But adding that capability of startswith/endswith makes the cut off something easy to get wrong and non-trivial to implement.</div><div dir="auto"><br></div><div dir="auto">That said, I really like Brandt's ideas of expanding the signature of .lstrip/.rstrip instead.</div><div dir="auto"><br></div><div dir="auto">mystring.rstrip("abcd") # remove any of these single character suffixes</div><div dir="auto"><br></div><div dir="auto">mystring.rstrip(('foo', 'bar', 'baz')) # remove any of these suffixes</div><div dir="auto"><br></div><div dir="auto">Yes, the semantics or removals where one is a substring of another would need to be decided. As long as it's documented, any behavior would be fine. Most of the time the issue would be moot.<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Sun, Mar 31, 2019, 4:36 AM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Mar 31, 2019 at 04:48:36PM +1100, Chris Angelico wrote:<br>
<br>
> Regardless of the method name, IMO the functions should accept a tuple<br>
> of test strings, as startswith/endwith do. That's a feature that can't<br>
> easily be spelled in a one-liner. (Though stacked suffixes shouldn't<br>
> all be removed - "asdf.jpg.png".cutsuffix((".jpg", ".png")) should<br>
> return "asdf.jpg", not "asdf".)<br>
<br>
There's a slight problem with that: what happens if more than one suffix <br>
matches? E.g. given:<br>
<br>
    "musical".lcut(('al', 'ical'))<br>
<br>
should the suffix "al" be removed, leaving "music"? (First match wins.)<br>
<br>
Or should the suffix "ical" be removed, leaving "mus"? (Longest match <br>
wins.)<br>
<br>
I don't think we can decide which is better, and I'm not keen on a <br>
keyword argument to choose one or the other, so I suggest we stick to <br>
the 90% solution of only supporting a single suffix.<br>
<br>
We can always revisit that in the future.<br>
<br>
<br>
-- <br>
Steven<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div></div>