after running the python script which will actually replace few values from one XML to another XML am seeing IOError: [Errno 13] Permission denied error:
Actual Code:
import os
from xml.etree.ElementTree import ElementTree
tree = ElementTree()
UN=(os.environ.get('UserProfile'))
actual = ("C:/Users/sam/Documents/hardware_settings_config.xml")
tree.parse ("C:/Users/sam/Documents/hardware_settings_config.xml")
root = tree.getroot()
ID=(root.attrib['MACID'])
tree.parse ("D:/LowSettings/hardware_settings_config.xml")
root = tree.getroot()
root.attrib['MACID'] = ID
tree.write('D:/LowSettings/hardware_settings_config.xml', xml_declaration=True)
import xml.etree.ElementTree as ET
tree = ET.parse("C:/Users/sam/Documents/hardware_settings_config.xml")
root = tree.getroot()
for child in root.findall('opu'):
for sub_c in child:
print (sub_c.attrib)
tree = ET.parse('D:/LowSettings/hardware_settings_config.xml')
root = tree.getroot()
for child in root.findall('opu'):
if child.find('Strategy') is None:
new=ET.SubElement(child,'Strategy')
for key, value in CID.items():
new.set(key, value)
tree.write("D:/LowSettings/hardware_settings_config.xml", xml_declaration=True)
Error:
Traceback (most recent call last):
File "C:\Users\sam\Music\ProfileGen.py", line 13, in <module>
tree.write('D:/LowSettings/hardware_settings_config.xml', xml_declaration=True)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 797, in write
file = open(file_or_filename, "wb")
IOError: [Errno 13] Permission denied: 'D:/LowSettings/hardware_settings_config.xml'
Any help is appreciated, thanks!
D:/DirtRally2/LowSettings/hardware_settings_config.xmlas done here: superuser.com/a/364085/524521