On 03Apr2019 14:54, Steven D'Aprano <st...@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 <c...@cskk.id.au>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/CED4UEOCA6JDGI356EJ4QYIUDIERGAET/
Code of Conduct: http://python.org/psf/codeofconduct/