Ian Bicking: the old part of his blog

Re: My first bit of ElementTree

"Another odd thing is that there's no way to serialize nodes to unicode --"..

this could help..

from cElementTree import Element, tostring

html = Element('html')

tostring(html, encoding='utf-8') # -> returns html node serialized into a string using specified encoding

Comment on My first bit of ElementTree
by daf

Comments:

Right, which is why I implemented a __unicode__ method like:

def __unicode__(self):
    return tostring(self, 'utf-8').decode('utf-8')

Doesn't that seem really weird, though?

# Ian Bicking