I'm making a game, and I want to use XML to store the data. How do I set variables based off an attribute from the xml tag using ElementTree
?
I have already tried assigning a variable objectEx-ssubchild.attrib = ssubchild.text
.
import os
import xml.etree.ElementTree as et
##vars
saveEx = "data\saveEx.xml"
base_path = os.path.dirname(os.path.realpath(__file__))
xml_file = os.path.join(base_path, saveEx)
##parsing
treeEx = et.parse(xml_file)
root = treeEx.getroot()
for child in root:
for subchild in child:
for ssubchild in subchild:
print(ssubchild.tag, "-", ssubchild.attrib, ":" , ssubchild.text)
objectEx-ssubchild.attrib = ssubchild.text ##where the error is
print(objectEx-charName)
I expected to get a variable called objectEx.charName
that holds the string '[name]
', however I get an error
can't assign to operator ([unknown], line 23)
I also want to add the fact that I am in no way shape or form 'good' at python. I understand the basics, and the game I am making is text only.