[Python-ideas] Revisiting str.rreplace()

Eric V. Smith eric at trueblade.com
Thu Jul 19 11:25:16 EDT 2018


On 7/19/2018 11:22 AM, 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?

It currently does something: it replaces all instances, just as if you 
hadn't supplied a count (see my example below). You can't change its 
behavior.

Eric

> 
> 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.
> 
>     Eric
> 
> 


More information about the Python-ideas mailing list