ich komme leider bei einer Aufgabe nicht mehr weiter. und zwar soll ich Elemente aus einer Liste auslesen und in eine andere Liste reinstellen. Dabei hab ich allerdings Probleme mit der for-Schleife. Es wäre nett, wenn mir dort jemand weiterhelfen könnte

Code: Alles auswählen
import xml.etree.ElementTree as xmltree
tree = xmltree.parse("xmlprogrammliste.xml")
doc = tree.getroot()
xpos = ""
ypos = ""
resx = ""
resy = ""
lastuser = ""
lastusage = ""
serialcode = ""
date = []
data = []
user = []
get_picture_format = []
get_picture_base64 = []
picture_name = []
def read_configuration():
configuration = doc.find("configuration")
position = configuration.find("position")
xpos = position.find("xpos").text
ypos = position.find("ypos").text
resolution = configuration.find("resolution")
resx = resolution.find("resx").text
resx = resolution.find("resy").text
lastuser = configuration.find("lastuser").text
lastusage = configuration.find("lastusage").text
serialcode = configuration.find("serialcode").text
def read_history():
history = doc.find("history")
for function in history.getchildren():
date.append(function.find("date").text)
data.append(function.find("data").text)
picture = function.find("picture")
picture_base64 = picture.find("base64")
get_picture_format.append(picture_base64.get("format"))
get_picture_base64.append(picture_base64.text)
picture_name.append(picture.find("name").text)
user.append(function.find("user").text)
def write_element():
read_configuration()
read_history()
writetree = xmltree.Element('dgraphconfig')
configuration = xmltree.SubElement(writetree, 'configuration')
position = xmltree.SubElement(configuration, 'position')
xpos_tree = xmltree.SubElement(position, 'xpos')
xpos_tree.text = xpos
ypos_tree = xmltree.SubElement(position, 'ypos')
ypos_tree.text = ypos
resolution = xmltree.SubElement(configuration, 'resolution')
resx_tree = xmltree.SubElement(resolution, 'resx')
resx_tree.text = resx
resy_tree = xmltree.SubElement(resolution, 'resy')
resy_tree.text = resy
lastuser_tree = xmltree.SubElement(configuration, 'lastuser')
lastuser_tree.text = lastuser
lastusage_tree = xmltree.SubElement(configuration, 'lastusage')
lastusage_tree.text = lastusage
serialcode_tree = xmltree.SubElement(configuration, 'serialcode')
serialcode_tree.text = serialcode
history = xmltree.SubElement(writetree, 'history')
function = []
date_tree = []
data_tree = []
picture = []
pic_name = []
pic_base64 = []
user_tree = []
for i in range(0, len(user) - 1):
function.append(xmltree.SubElement(history, 'function'))
date_tree.append(xmltree.SubElement(function[i], 'date'))
date_tree[i].text = date[i]
data_tree.append(xmltree.SubElement(function[i], 'data'))
data_tree[i].text = data[i]
picture.append(xmltree.SubElement(function[i], 'picture'))
pic_name.append(xmltree.SubElement(picture[i], 'name'))
pic_name[i].text = picture_name
pic_base64.append(xmltree.SubElement(picture[i], 'base64'))
pic_base64[i].set('format', get_picture_format[i])
pic_base64[i].text = get_picture_base64[i]
user_tree.append(xmltree.SubElement(function[i], 'user'))
user_tree[i].text = user[i]
tree = xmltree.ElementTree(writetree)
tree.write("xmlbeispiel.xml")
#read_history()
write_element()
Traceback (most recent call last):
File "/home/justin/Dokumente/xml-parser_readandwrite.py", line 116, in <module>
write_element()
File "/home/justin/Dokumente/xml-parser_readandwrite.py", line 113, in write_element
tree.write("xmlbeispiel.xml")
File "/usr/lib/python3.2/xml/etree/ElementTree.py", line 862, in write
serialize(write, self._root, qnames, namespaces)
File "/usr/lib/python3.2/xml/etree/ElementTree.py", line 978, in _serialize_xml
_serialize_xml(write, e, qnames, None)
File "/usr/lib/python3.2/xml/etree/ElementTree.py", line 978, in _serialize_xml
_serialize_xml(write, e, qnames, None)
File "/usr/lib/python3.2/xml/etree/ElementTree.py", line 978, in _serialize_xml
_serialize_xml(write, e, qnames, None)
File "/usr/lib/python3.2/xml/etree/ElementTree.py", line 978, in _serialize_xml
_serialize_xml(write, e, qnames, None)
File "/usr/lib/python3.2/xml/etree/ElementTree.py", line 976, in _serialize_xml
write(_escape_cdata(text))
File "/usr/lib/python3.2/xml/etree/ElementTree.py", line 845, in write
_raise_serialization_error(text)
File "/usr/lib/python3.2/xml/etree/ElementTree.py", line 1091, in _raise_serialization_error
"cannot serialize %r (type %s)" % (text, type(text).__name__)
TypeError: cannot serialize [None, None] (type list)