[Python-Dev] Minidom and Unicode
Fredrik Lundh
Fredrik Lundh" <effbot@telia.com
Mon, 3 Jul 2000 11:54:25 +0200
martin wrote:
> In what way?
>=20
> Python 2.0b1 (#1, Jul 3 2000, 09:12:07) [GCC 2.95.2 19991024 =
(release)] on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> Copyright 1995-2000 Corporation for National Research Initiatives =
(CNRI)
> >>> class X:
> ... def __repr__(self):
> ... if hasattr(self,"u"):
> ... return u'\u30b9'
> ... else:
> ... return u'hallo'
> ...=20
> >>> x=3DX()
> >>> x
> hallo
> >>> x.u=3D1
> >>> x
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: __repr__ returned non-string (type unicode)
>=20
> > no need to change minidom.
>=20
> The need still appears to exist, both for minidom.Element (KATAKANA
> LETTER SU is a letter, and thus a valid tag name), as well as
> minidom.Text. A string is a string is a string.
works for me:
$ export LANG=3Dposix.utf8
$ python
>>> import sys
>>> sys.getdefaultencoding()
'utf8'
>>> class X:
... def __repr__(self):
... return u"u\30b9"
...
>>> x =3D X()
>>> x
=E3,=B9
(or to put it another way, I'm not sure the repr/str fix is
the real culprit here...)
</F>