str.replace is in the opposite situation: 1. People usually want to replace everything. When I search for uses of replace in code, I can't find any uses of the count parameter. 2. People are more likely to accidentally notice that everything is being replaced the string being replaced is much more likely to appear multiple times, because: 1. It can appear anywhere in the string, whereas multiple consecutive prefixes is unlikely 2. It's often a single character, as opposed to something like a folder name. 3. I'm speculating here, but I think people are more likely to ask themselves "what if the string I want to replace appears multiple times" than "what if the prefix I want to remove appears multiple times in a row". That's a very edge edge case. On Wed, Mar 18, 2020 at 8:58 PM Rob Cliffe <rob.cliffe@btinternet.com> wrote:
Well, str.replace has a count parameter. Presumably people use it (even if by accidentally discovering that without it, it replaces all occurrences when they only wanted one replaced). On 18/03/2020 18:44, Alex Hall wrote:
Just the first occurrence. The vast majority of the time, that's what people want to do, and they will usually forget to add a 'count' parameter. Many people probably wouldn't even know it exists. It would be disastrous if code did the correct thing 99.9% of the time but occasionally silently mutilated a string.
On Wed, Mar 18, 2020 at 8:06 PM Rob Cliffe via Python-ideas < python-ideas@python.org> wrote:
Consider that the start or end of a string may contain repetitions of an affix.
Should `-+-+-+Spam'.stripprefix('-+') remove just the first occurence? All of them? Does it need a 'count' parameter?
[all modulo bikeshedding on the names of course]
Rob Cliffe
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/JMWBL7... Code of Conduct: http://python.org/psf/codeofconduct/