[Python-ideas] Revisiting str.rreplace()

MRAB python at mrabarnett.plus.com
Thu Jul 19 11:38:35 EDT 2018


On 2018-07-19 16:22, Calvin Spealman wrote:
> If its treated as a missing parameter, and currently doesn't do 
> anything, then it wouldn't be used... right? and it could be safe to add 
> behavior for it... right?
> 
Are you sure that it wouldn't break some existing code?

Plus, we already have .find/.rfind, .index/.rindex, etc, so 
.replace/.rreplace would be a better fit.

> On Thu, Jul 19, 2018 at 11:17 AM, Eric V. Smith <eric at trueblade.com 
> <mailto:eric at trueblade.com>> wrote:
> 
>     On 7/19/2018 10:01 AM, Calvin Spealman wrote:
> 
>         As an alternative suggestion: What if the count parameter to
>         str.replace() counted from the right with negative values? That
>         would be consistent with other things like indexing and slicing.
> 
> 
>     We couldn't make this change because negative values already have a
>     meaning: it's interpreted as a missing parameter:
> 
>      >>> 'abab'.replace('a', 'z')
>     'zbzb'
>      >>> 'abab'.replace('a', 'z', 0)
>     'abab'
>      >>> 'abab'.replace('a', 'z', 1)
>     'zbab'
>      >>> 'abab'.replace('a', 'z', -1)
>     'zbzb'
>      >>> 'abab'.replace('a', 'z', -2)
>     'zbzb'
>      >>> 'abab'.replace('a', 'z', -100)
>     'zbzb'
> 
>     I think .rreplace() is the better design.
> 


More information about the Python-ideas mailing list