James Franco
James Franco

Reputation: 4706

Python ElementTree : write to the file it is parsing already

I am currently writing my XML to another file in the following manner

filepath = folderName + "/config.xml"
config = ET.parse(filepath)
...
config.write(open(folderName + "/config.xml", 'w+b'))

My question is how can I write to the same file that is currently open by ET ?

Upvotes: 1

Views: 72

Answers (1)

alecxe
alecxe

Reputation: 473863

You can provide the path to the same file you've used to read the XML data from:

config.write(filepath)

Upvotes: 1

Related Questions