This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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
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 2022-04-11 14:58 by admin. 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,')

I suspect it is starting the second search at the start of the first find + length of the find? ie:
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.
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70117
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