newbie problem with str.replace
Peter Otten
__peter__ at web.de
Wed Aug 4 09:22:22 EDT 2010
BobAalsma wrote:
Although [it] may not be obvious at first unless you're Dutch...
> bestandsnaam_nieuw = bestandsnaam
> bestandsnaam_nieuw.replace(KLANTNAAM_OUT,KLANTNAAM_IN)
str.replace() does not modify a string, it creates a new one.
This doesn't work:
>>> s = "that's all folks"
>>> s.replace("all", "nothing")
"that's nothing folks"
>>> s
"that's all folks"
But this does:
>>> old = "that's all folks"
>>> new = old.replace("all", "nothing")
>>> new
"that's nothing folks"
Peter
More information about the Python-list
mailing list