ElementTree and proper identation?
Robert Kern
robert.kern at gmail.com
Wed Sep 27 14:46:57 EDT 2006
John Salerno wrote:
> John Salerno wrote:
>> Yeah, actually I just gave this a try but I couldn't figure out where
>> the code needed to go or how to call the function. I tried creating an
>> Element with a few SubElements, then I did:
>>
>> print >> filename, indent(root)
>>
>> But that only wrote the value "None" into the file.
>
> Ok, I see that indent() returns None. In that case, how do I get the
> formatted text that it produces?
The indent() function modifies the elements themselves to add the indentation.
So dump the tree to a string.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list