[New-bugs-announce] [issue25929] When doing string.replace, it uses the entire 'find' string and doesn't let it get reused...

Mark Cline report at bugs.python.org
Tue Dec 22 17:55:10 EST 2015


New submission from Mark Cline:

The Title might be a bit awkward but this is what I mean:

before = ',,,,'
after = before.replace(',,', ',null,')
print(after)
>,null,,null,

I suspect it is starting the second search at the start of the first find + length of the find? ie:
,,,,
0123
Starting the next search at spot 2 (the 3rd ,).

This might be expected behaviour as it is looking at the rest of the string after finding the match, as opposed to taking the updated string:
,null,,, after the first replace. (Actually, writing that out it does make sense that it would behave like this, but thought I would mention just in case I am missing something). 

[Its easy enough to work around it, but just thought I would mention it :D]

----------
components: Library (Lib)
messages: 256877
nosy: Mark Cline
priority: normal
severity: normal
status: open
title: When doing string.replace, it uses the entire 'find' string and doesn't let it get reused...
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25929>
_______________________________________


More information about the New-bugs-announce mailing list