>>> import xml.etree.ElementTree as etree
>>> import csv
>>> import sys
>>>
>>> text = """\
... <Root>
... <SubRoot>
... <Level1>A</Level1>
... <Level2>B</Level2>
... <Level3>C</Level3>
... <Level4>D</Level4>
... </SubRoot>
...
... <SubRoot>
... <Level1>1</Level1>
... <Level2>2</Level2>
... <Level3>3</Level3>
... </SubRoot>
... </Root>
... """
>>>
>>> root = etree.fromstring(text)
>>>
>>> out = [[i.text for i in node] for node in root]
>>> out
[['A', 'B', 'C', 'D'], ['1', '2', '3']]
>>>
>>> out = [(i + [None] * (4 - len(i))) for i in out]
>>> out
[['A', 'B', 'C', 'D'], ['1', '2', '3', None]]
>>>
>>> writer = csv.writer(sys.stdout)
>>> writer.writerows(out)
A,B,C,D
1,2,3,
>>>