[lxml-dev] Pretty print indent level

Here's a little snippet of what I'm doing: from lxml import etree doc = etree.parse(file) text = etree.tostring(doc, pretty_print=True) ... So, that works great and outputs a nicely formatted XML document. However, the indent level of pretty_print is 2 spaces whereas I'd like 4 spaces. Is there any way to control the number of spaces per indent level?

Isaac Wagner, 08.06.2010 18:40:
Here's a little snippet of what I'm doing:
from lxml import etree doc = etree.parse(file) text = etree.tostring(doc, pretty_print=True) ...
So, that works great and outputs a nicely formatted XML document. However, the indent level of pretty_print is 2 spaces whereas I'd like 4 spaces. Is there any way to control the number of spaces per indent level?
Potentially, yes, libxml2 supports this. But it's not available through the lxml.etree API. Note that there is a little indent() function on effbot's ElementTree site that implements pretty printing at the user level. Works fine with lxml. Stefan
participants (2)
-
Isaac Wagner
-
Stefan Behnel