Thanks. I was wondering what happened to that idea. I’d like to see it revived, it seems a perfectly reasonable addition to the string object to me. And now you’ve written a prototype, there’s a straightforward proposal. -CHB On Wed, Mar 4, 2020 at 4:54 PM Cameron Simpson <cs@cskk.id.au> wrote:
On 03Apr2019 14:54, Steven D'Aprano <steve@pearwood.info> wrote:
Now imagine it's five years from now, and you're using Python 3.11, and you came across code somebody (possibly even you!) wrote:
ifname = ifname.cutsuffix(':')
Would you say "Damn, I wish that method had never been added!" and replace it with the earlier code above?
Just a late followup to this thread.
The other month I found myself doing the endwith/s=s[:-n] shuffle yet again, and wrote a pair of cutprefix and cutsuffix functions. They're available in my "cs.lex" PyPI module if anyone wants to use them. Their signature is:
prefix = cutsuffix(original_string, suffix) if prefix is original_string: # suffix not present ... else: # suffix present, proceed using prefix
and the converse for cutprefix.
Cheers, Cameron Simpson <cs@cskk.id.au> _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CED4UE... Code of Conduct: http://python.org/psf/codeofconduct/
-- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython