
Hello, On Tue, 24 Mar 2020 19:14:16 +0100 Victor Stinner <vstinner@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:pmiscml@gmail.com