tags:

views:

157

answers:

3

Basically I am using:

from xml.etree import ElementTree as ET

path = 'C:\cool.xml'
et = ET.parse ( path )

But I am not sure how to get the root from et?

+8  A: 

You probably want:

et.getroot()

Have a look at the official docs for ElementTree from the effbot site. Note that Python 2.5 (the first version of Python to include ElementTree out of the box) uses ElementTree 1.2, not the more recent 1.3. There aren't many differences, but just FYI in case.

Jarret Hardie
+1: Link to the documentation.
S.Lott
+2  A: 
root = et.getroot()
jcoon
+4  A: 
root = et.getroot()

I would recommend using lxml.etree instead of xml.etree.ElementTree, as lxml is faster and the interface is the same.

sysrqb
There is no syntactical difference?
Joan Venge
+1 for lxml suggestion
jcoon