[issue11033] ElementTree.fromstring doesn't work with Unicode
Alexander Belopolsky
report at bugs.python.org
Wed Feb 2 17:08:44 CET 2011
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
This works in 3.x:
Python 3.2rc2+ (py3k:88279:88280, Feb 1 2011, 00:01:52)
..
>>> from xml.etree import ElementTree
>>> ElementTree.fromstring('<doc>诗</doc>')
<Element 'doc' at 0x1007daa00>
In 2.x you need to encode unicode strings before passing them to ElementTree.fromstring(). For example:
----
# encoding: utf-8
from xml.etree import ElementTree
t = ElementTree.fromstring(u'<doc>诗</doc>'.encode('utf-8'))
print t.text
----
This is not a bug because fromstring() unlike some other ElementTree methods is not documented to support unicode strings. Since 2.x is closed for new features, this has to be rejected.
----------
assignee: -> belopolsky
nosy: +belopolsky
resolution: -> rejected
stage: -> committed/rejected
status: open -> pending
type: crash -> feature request
versions: +Python 2.7 -Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11033>
_______________________________________
More information about the Python-bugs-list
mailing list