[Python-ideas] New explicit methods to trim strings

Anders Hovmöller boxed at killingar.net
Sun Mar 31 01:53:53 EDT 2019

> Steven D'Aprano:
> Stephen J. Turnbull:
>> And the bikeshedding isn't hard.  In the list above, cutprefix/
>> cutsuffix are far and away the best.
> Well I'm glad we agree on that, even if nothing else :-)

I prefer “strip_prefix” because of the analogy to strip() which doesn’t do anything if the characters aren’t present. Introducing a new word “cut” seems unnecessary and confusing and I’d wager it will increase the probability of:

if s.startswith(‘foo’):
	s = s.cutprefix(‘foo’)

Obviously this is a guess!

I also don’t understand why not using the underscore is preferable? It seems just to be poor form.

/ Anders

More information about the Python-ideas mailing list