classification
Title: When doing string.replace, it uses the entire 'find' string and doesn't let it get reused...
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Mark Cline, r.david.murray
Priority: normal Keywords:

Created on 2015-12-22 22:55 by Mark Cline, last changed 2015-12-23 01:05 by r.david.murray. This issue is now closed.

Messages (2)
msg256877 - (view) Author: Mark Cline (Mark Cline) Date: 2015-12-22 22:55
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]
msg256892 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-12-23 01:05
No, you aren't missing anything, it is working as designed.
History
Date User Action Args
2015-12-23 01:05:26r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg256892

resolution: not a bug
stage: resolved
2015-12-22 22:55:10Mark Clinecreate