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.

classification
Title: string.replace(' ',' ') has to be called 2 times before it works
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, ethan.furman, orsenthil, roland_eichman
Priority: normal Keywords:

Created on 2016-01-06 12:26 by roland_eichman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg257603 - (view) Author: Roland Eichman (roland_eichman) Date: 2016-01-06 12:26
Windows 10 
python 3.5
small function in a small module 
contained a string len(str1) == 5000 {approx}
str1 = str1.replace('  ',' ')
did not work
added, via copy & paste, a second identical line
str1 = str1.replace('  ',' ')
str1 = str1.replace('  ',' ')
AND IT WORKED
msg257604 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-01-06 12:31
Could you provide us with a sample file that demonstrates this behaviour?
msg257605 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-06 12:43
Please use stackoverflow or python-tutor list to get help on this.
https://mail.python.org/pipermail/tutor/

This is unlikely a problem as you are using replace the send time on new string object.
msg257607 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-01-06 13:55
The .replace() method is not recursive (it only makes one pass through the string), so for example:

>>> example = '   '  # three spaces
>>> example = example.replace('  ', ' ')  # replace two spaces with one space
>>> example  # should be two spaces
'  '  
>>> example = example.replace('  ', ' ')  # replace two spaces with one space
>>> example  # should be one space
' '
History
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70210
2016-01-06 13:55:01ethan.furmansetnosy: + ethan.furman
resolution: rejected -> not a bug
messages: + msg257607
2016-01-06 12:43:22orsenthilsetstatus: open -> closed

nosy: + orsenthil
messages: + msg257605

resolution: rejected
stage: resolved
2016-01-06 12:31:03SilentGhostsetnosy: + SilentGhost
messages: + msg257604
2016-01-06 12:26:47roland_eichmancreate