[Python-ideas] New explicit methods to trim strings

Anders Hovmöller boxed at killingar.net
Mon Apr 1 01:07:34 EDT 2019

> On 1 Apr 2019, at 02:23, David Mertz <mertz at gnosis.cx> wrote:
>> 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.

Doing this with a for loop and without_suffix is fine though. Without without_suffix it's suddenly error prone. With a without_suffix that takes a typle it's unclear what happens without reading the code. 

I think a single string argument is a great sweet spot: avoid the most error prone part and keep the loop in user code.

/ Anders 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190401/fe83f9d2/attachment-0001.html>

More information about the Python-ideas mailing list