[Python-ideas] New explicit methods to trim strings

David Mertz mertz at gnosis.cx
Sun Mar 31 20:23:05 EDT 2019


On Sun, Mar 31, 2019, 8:11 PM Steven D'Aprano <steve at pearwood.info> wrote:

> Regarding later proposals to add support for multiple affixes, to
> recursively delete the affix repeatedly, and to take an additional
> argument to limit how many affixes will be removed: YAGNI.
>

That's simply not true, and I think it's clearly illustrated by the example
I gave a few times. Not just conceivably, but FREQUENTLY I write code to
accomplish the effect of the suggested:

  basename = fname.rstrip(('.jpg', '.gif', '.png'))

I probably do this MORE OFTEN than removing a single suffix.

Obviously I *can* achieve this result now. I probably take a slightly
different approach as the mood strikes me, with three or four different
styles I've used. Actually, I've probably never done it in a way that
wouldn't be subtly wrong for cases like 'base.jpg.gif.png.jpg.gif'.

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190331/25cf6dd0/attachment.html>


More information about the Python-ideas mailing list