string.replace() question

Per Jensen per at
Tue Jan 7 09:58:58 CET 2003

The Python doc on string.replace says this:

replace(str, old, new[, maxsplit])
"""Return a copy of string str with all occurrences of substring old
replaced by new. If the optional argument maxsplit is given,
the first maxsplit occurrences are replaced."""

I must have a blind spot, but the method doesn't seem to work quite like
that. Example:

bash-2.05$ python
Python 2.2.1 (#1, Sep 24 2002, 21:50:51)
[GCC 2.95.3 20010315 (SuSE)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> string.replace("C:\py21\gallery\resized", "\\", "/")

Notice that the last "\" is not replaced with a "/"

My question is why ?


Per Jensen         Linux rules! 

More information about the Python-list mailing list