[docs] xml.etree.ElementTree.tostring

Quarante-Deux xlii at xlii.org
Fri Dec 7 08:29:18 CET 2012


Hello,

For http://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring

could you please add that if the tag of the element is set to None, said tag is omitted in the resulting bytes:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11)
from xml.etree.ElementTree import fromstring, tostring

e = fromstring('<xml><i>example</i> accentué</xml>')

tostring(e) -->  b'<xml><i>example</i> accentué</xml>'

e.tag = None

tostring(e) -->  b'<i>example</i> accentué'

Very handy in a templating context.

Also, tostring returns bytes and should be named tobytes, actually :-)

If what you really want is a string you should use :

tostring(e, encoding='unicode') -->  '<i>example</i> accentué'

Hum…

Thank you.




Quarante-Deux: quelques pages sur la SF
Ellen C. Herzfeld - Dominique O. Martel
http://www.quarante-deux.org/ - @xlii42
http://www.quarante-deux.org/index.atom



More information about the docs mailing list