Hi,
Replacing strings in a text (likely an XML) file. Some newbie
questions...
...
while line:
counter=counter+1
if line.find(newstring) != -1:
print 'match at line'+str(counter)
newline = line.replace(oldstring, newstring)
fileOUT.write(newline)
goldtech [EMAIL PROTECTED] wrote:
Question1: The replace method - If a string does not have the target
replacement newstring, then newline equals oldstring? Ie. oldstring
is not changed in any way? Seems to be what I observe but just want to
confirm this.
Yes.
Question2: I'm using
snip...
for counter, line in enumerate(fileIN):
newline = line.replace(oldstring, newstring)
if newline != line:
print 'match at line', counter+1
fileOUT.write(newline)
enumerate - haven't seen that before. Nice!
Thanks
--