Say there's a variable
x = "/real/path/"
inside a text file "setting.txt", and in a config xml file "config.xml" contains a tag
<root>
<setting>setting.txt</setting>
......
</root>
In my Python script test.py, I would like to do this:
import xml.etree.ElementTree as ET
import os
x = "/path/placeholder"
def load_global_setting_from_config_xml(in_xml):
tree = ET.parse(in_xml)
root = tree.getroot()
config_node = root.find("setting")
if config_node is not None:
config_file_path = config_node.text
if os.path.exists(config_file_path):
execfile(config_file_path) # looks not working
load_global_setting_from_config_xml("config.xml")
print(x) #expected output is /real/path
it looks execfile() does not working.