Re: replacing string in xml file
- From: "Carsten Haese" <carsten@xxxxxxxxxxx>
- Date: Tue, 8 May 2007 07:45:01 -0400
On Tue, 08 May 2007 13:30:59 +0200, Stefan Behnel wrote
saif.shakeel@xxxxxxxxx schrieb:
[...]
file_input = raw_input("Enter The ODX File Path:")
input_xml = open(file_input,'r')
This should say
input_xml = open(file_input,'r').read()
....and then it still won't work because the OP's replace call assumes in-place
operation despite the fact that strings aren't mutable.
The OP needs something following this pattern:
input_file = open(filename)
xmlcontents = input_file.read()
input_file.close()
xmlcontents = xmlcontents.replace("spam", "eggs")
output_file = open(filename,"w")
output_file.write(xmlcontents)
output_file.close()
For extra credit, use a different file name for writing out the result and
rename the file after it's written. That way you don't lose your file contents
if a meteor hits your CPU just after it started to overwrite the file.
Best regards,
--
Carsten Haese
http://informixdb.sourceforge.net
.
- References:
- replacing string in xml file
- From: saif . shakeel
- Re: replacing string in xml file
- From: Stefan Behnel
- replacing string in xml file
- Prev by Date: Re: replacing string in xml file
- Next by Date: Re: replacing string in xml file
- Previous by thread: Re: replacing string in xml file
- Next by thread: Re: replacing string in xml file
- Index(es):
Relevant Pages
|