<div dir="auto">I like this idea quite a lot. I do not think of anything it works best at first consideration.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 30, 2019, 8:28 PM Brandt Bucher <<a href="mailto:brandtbucher@gmail.com">brandtbucher@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> One thing I love about .startswith() and .endswith() is matching multiple options. It's a little funny the multiple options must be a tuple exactly (not a list, not a set, not an iterator), but whatever. It would be about to lack that symmetry in the .cut_suffix() method.<br>
> <br>
> E.g now:<br>
> <br>
> if fname.endswith(('.jpg', '.png', '.gif)): ...<br>
> <br>
> I'd expect to be able to do:<br>
> <br>
> basename = fname.cut_suffix(('.jpg', '.png', '.gif))<br>
<br>
An idea worth considering: one can think of the “strip” family of methods as currently taking an iterable of strings as an argument (since a string is itself an sequence of strings):<br>
<br>
>>> "abcd".rstrip("dc")<br>
'ab'<br>
<br>
It would not be a huge logical leap to allow them to take any iterable. Backward compatible, no new methods:<br>
<br>
>>> fname.rstrip(('.jpg', '.png', '.gif'))<br>
<br>
It even, in my opinion, can clarify "classic" strip/rstrip/lstrip usage:<br>
<br>
>>> "abcd".rstrip(("d", "c"))<br>
'ab'<br>
<br>
Maybe I’m missing a breaking case though, or this isn’t as clear for others. Thoughts?<br>
<br>
Brandt<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>