On Sat, Mar 7, 2020 at 7:06 AM Ethan Furman <et...@stoneleaf.us> wrote:

> On 03/07/2020 05:31 AM, Alex Hall wrote:
>
> > I've defined functions like this in my own utility library and I use them
> >  all the time, so I think they're very useful and would like to seem them
> >  built in. But I have two functions for each end:
> >
> > def strip_optional_suffix(string, suffix):
> >      ...
> >
> > def strip_required_suffix(string, suffix):
> >      ...
> >
> > And I know that I use the required versions much more often, because
> >  usually if the suffix isn't there that indicates a bug somewhere that I
> >  need to know about. So I'd like to have both the optional and required
> >  versions implemented in this proposal, and if that's too much to add
> then
> >  just the required versions. But I suspect most people will be against
> the
> >  idea.
>
> Against only having the required versions, yes.  However, we do have other
> functions that take an extra parameter to determine whether to raise an
> exception, so perhaps:
>
>      def strip_suffix(string, /, required=False):
>          ...
>

Maybe. FWIW, I looked at what a few other languages offer, and found that
in Go, they use Trim(s, chars) for our s.strip(chars), and they have
separate TrimPrefix and TrimSuffix methods. That seems the best solution of
the bunch, so I am now okay with using stripprefix and stripsuffix. (Why no
_? Because startswith and endswith don't have one either.)

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
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/QXUHMIYIAELULVB5T75AQXCMMH6I2EAS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to