3

I'm getting an error from the following code:

import xml.etree.ElementTree as ET

tree = ET.ElementTree()
root = ET.Element("configuration")
elem = ET.SubElement(root, "appConfig")
elem2 = ET.SubElement(root, "fileGDB")
print ET.tostring(root)
tree.write(sys.stdout)

It throws an exception on the following line in the ElementTree.py module: iterate = elem.getiterator # cET compatibility The exception is: AttributeError: 'NoneType' object has no attribute 'getiterator'

In the code above:

print ET.tostring(root)

prints out just fine. I don't understand why it's throwing this exception. What am I doing wrong?

Steve

1 Answer 1

6

Okay duh, I needed to make the following line the last after creating nodes:

tree = ET.ElementTree(root)

Maybe someone else will be as numbskull as I was. :-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.