On Sun, Mar 22, 2020 at 2:08 AM Barry Scott <[email protected]> wrote:
> >>> Should `-+-+-+Spam'.stripprefix('-+') remove just the first
> occurence? All of them? Does it need a 'count' parameter?
> >> The only ways to use this function without counting is remove 1 prefix
> or remove all.
>
I imagine that the count=1 is the most common use case for replace()
anyway,
So it seems it would be useful to have a way to select either "one" or
"all". Once we have that, why not "count", and -1 means "all", just like it
does for .replace() -- after all, why introduce yet another API?
That being said, I'd be just as happy with only one.
On a related note, I just noticed:
In [8]: s.replace('a', 'x', count=2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-ef1478a5d3cb> in <module>
----> 1 s.replace('a', 'x', count=2)
TypeError: replace() takes no keyword arguments
having count be a keyword parameter seems like the natural API to me. Is is
just legacy that it's not? Is there a good reason not to make it a keyword
parameter? (it is optional).
Frankly, that's always been confusing -- particularly as until 3.8 you
couldn't make a function with a default and not a keyword at all.
-CHB
--
Christopher Barker, PhD
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/QVTFWNBWCPYPTH5FBAIVU4MIHBHAHPT4/
Code of Conduct: http://python.org/psf/codeofconduct/