pretty-print

Changing the default indentation of etree.tostring in lxml

Changing the default indentation of etree.tostring in lxml Question: I have an XML document which I’m pretty-printing using lxml.etree.tostring print etree.tostring(doc, pretty_print=True) The default level of indentation is 2 spaces, and I’d like to change this to 4 spaces. There isn’t any argument for this in the tostring function; is there a way to do …

Total answers: 4

Pretty printing XML in Python

Pretty printing XML in Python Question: What is the best way (or are the various ways) to pretty print XML in Python? Asked By: Hortitude || Source Answers: XML pretty print for python looks pretty good for this task. (Appropriately named, too.) An alternative is to use pyXML, which has a PrettyPrint function. Answered By: …

Total answers: 27

How do I get python's pprint to return a string instead of printing?

How do I get python's pprint to return a string instead of printing? Question: In other words, what’s the sprintf equivalent to pprint? Asked By: drue || Source Answers: The pprint module has a function named pformat, for just that purpose. From the documentation: Return the formatted representation of object as a string. indent, width …

Total answers: 5