[Python-ideas] str.rreplace
Ron Adam
ron3200 at gmail.com
Tue Jan 28 18:43:21 CET 2014
On 01/28/2014 06:33 AM, Steven D'Aprano wrote:
> On Mon, Jan 27, 2014 at 08:03:54PM -0800, Andrew Barnert wrote:
>> From: Ron Adam <ron3200 at gmail.com>
>
>>> How about a keyword to specify which end to index from?
>
> -1
>
> As a general rule, when you have a function that takes a parameter which
> selects between two different sets of behaviour, and you normally
> specify that parameter as a literal or constant known at edit time, then
> the function should be split into two.
>
> E.g.:
>
> # Good API
> string.upper(), string.lower()
>
> # Bad API
> string.convert_case(to_upper=True|False)
You are correct, and I got my methods mixed up this morning ... I was
thinking of __getitem__ instead of index. And related methods.
The issues I was referring to are not directly related as you pointed out.
In most cases I do think having separate functions or methods is better.
And in this case it's no different than having partition and rrpartition.
I think the argument against rreplace and the strangeness of it's name is
too late. There are already a fair number of "r" methods.
Cheers,
Ron
More information about the Python-ideas
mailing list