Strings
Oleg Broytmann
phd at phd.pp.ru
Fri Jan 18 06:51:29 EST 2002
On Fri, Jan 18, 2002 at 11:42:31AM -0000, maximilianscherr wrote:
> ok, i have a string like this: "C:/Programs/.../.../"
> now i need to have all the "/"s to be "\"s. how can i do this
Foreword: please be advised that backslash is a special character for
the Python interpreter (nad for many others). So DOUBLE backslashes that
you pass to compiler/interpreter.
Now to the tas. It's easy:
s = "C:/Windows/MustDie"
print s.replace('/', '\\') # note double backslash
This solution requires Python 2.0+. For 1.5.2 use string.replace(s, '/', '\\')
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-list
mailing list