if len(elem):
    if not elem.text or not elem.text.strip():
        elem.text = i + '  '
if not elem.tail or not elem.tail.strip():
    elem.tail = i
for elem in elem:
    pass
Changing the default indentation of etree.tostring in lxml