Gotcha in replace
tjenkins at devis.com
Sun Jul 8 05:47:39 CEST 2001
While I was working on some database scripting, I got bit by this
behavior in replace.
>>> y = "insert into blah values ('hello','','','','bye')"
>>> y.replace(",'',", ",' ',")
"insert into blah values ('hello',' ','',' ','bye')"
Notice that the second matching set of ",''," characters are not
replaced probably because the first and second matching sets overlap on
the last and first character, respectively.
It was trivial for this script to work around the gotcha (I just put the
replace in a loop and broke out when new string equalled the old
string). But that method may not be an appropriate workaround in all cases.
Is this known behavior and I just missed it; or is this a bug in replace?
devIS - Development Infostructure
More information about the Python-list