Hello,

On Tue, 24 Mar 2020 19:14:16 +0100
Victor Stinner <vstin...@python.org> wrote:

[]

> The behavior of tuple containing an empty string is a little bit
> surprising.
> 
> cutsuffix("Hello World", ("", " World")) returns "Hello World",
> whereas cutsuffix("Hello World", (" World", "")) returns "Hello".
> 
> cutprefix() has a the same behavior: the first empty strings stops the
> loop and returns the string unchanged.
> 
> I would prefer to raise ValueError("empty separator") to avoid any
> risk of confusion. I'm not sure that str.cutprefix("") or
> str.cutsuffix("") does make any sense.

str.cutprefix("")/str.cutsuffix("") definitely makes sense, e.g.:

=== config.something ===
# If you'd like to remove some prefix from your lines, set it here
REMOVE_PREFIX = ""
======

=== src.py ===
...
line = line.cutprefix(config.REMOVE_PREFIX)
...
======


Now one may ask whether str.cutprefix(("", "nonempty")) makes sense.
A response can be "the more complex functionality, the more complex
and confusing corner cases there're to handle".

[]

-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/3M23LCIYMJ4TEQ6GNMHD4NJKTYBMDGGZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to