the tostring and XML methods in ElementTree
Fredrik Lundh
fredrik at pythonware.com
Mon May 8 04:43:32 EDT 2006
mirandacascade at yahoo.com wrote:
> I wanted to see what would happen if one used the results of a tostring
> method as input into the XML method. What I observed is this:
> a) beforeCtag.text is of type <type 'str'>
> b) beforeCtag.text when printed displays: I'm confused
> c) afterCtag.text is of type <type 'unicode'>
> d) afterCtag.text when printed displays: I?m confused
the XML file format isn't a Python string serialization format, it's an XML infoset
serialization format.
as stated in the documentation, ET always uses Unicode strings for text that
contain non-ASCII characters. for text that *only* contains ASCII, it may use
either Unicode strings or 8-bit strings, depending on the implementation.
the behaviour if you're passing in non-ASCII text as 8-bit strings is undefined
(which means that you shouldn't do that; it's not portable).
to learn more about Unicode in Python, google for "python unicode".
</F>
More information about the Python-list
mailing list