I'm trying to run the following code using Spyder in Anaconda 4.1.12 (Python 2.7):
import xml.etree.ElementTree as ET
tree = ET.parse("path/file")
root = tree.getroot()
for report in root.iter('Name'):
print(report)
tag = report.find('Name2')
print(tag)
for group in report.iter('Name3'):
for tx in group:
print('FOUND')
print(tx)
tx.append(tag)
with open("path/output",'w') as f:
f.write(ET.tostring(root))
For some reason I'm getting one of two errors.
1) IOError: [Errno 22] invalid mode ('w') or filename:
I've double checked that the path is correct and to my knowledge I have to include ('w') to write the file.
2) The program will halt half way through and I have to reset the console
Does anything look incorrect?