Edit: Have you named your script:
xml.py? Change it and it should work.
As a workaround, you could use
etree in the lxml package. If you don't have
lxml installed, type:
sudo apt-get install python-lxml
And for the modified version of your program:
import lxml.etree as ET
root = ET.Element("root")
doc = ET.SubElement(root, "doc")
field1 = ET.SubElement(doc, "field1")
field1.text = "some value1"
field2 = ET.SubElement(doc, "field2")
field2.text = "some vlaue2"
tree = ET.ElementTree(root)
<field1 name="blah">some value1</field1>
<field2 name="asdfasd">some vlaue2</field2>
For differences between the two solutions,
ElementTree, have a look at this doc lxml.etree versus ElementTree.
cElementTree is slightly faster compared to
lxml.etree, anyway the latter is still a fast xml parser written in C, and I think the difference is negligible (benchmarks here).