[Pythonmac-SIG] Unicode
Stuart Bishop
stuart at stuartbishop.net
Thu Mar 25 02:27:42 EST 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 21/03/2004, at 2:28 AM, Philippe de Rochambeau wrote:
> Hello,
>
> I can't get python 2.3 to work with unicode strings. For instance,
>
> print u"El\xE9phant"
>
> results in
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> UnicodeEncodeError: 'ascii' codec can't encode character '\ue9' in
> position 2: ordinal not in range(128)
> >>>
>
> any help would be much appreciated.
You can't output a Unicode string without encoding it.
print u'El\xE9phant'.encode('utf8')
Replace utf8 with the character set your terminal window is
configured to use (Cmd-I and select 'display'). I'd suggest
setting this to utf8 as this can encode all Unicode strings, unlike
other common ones like latin-1, macroman or cp1252.
- --
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)
iD8DBQFAYon0AfqZj7rGN0oRAhd5AKCQKWah7HhBCrQ0xTL+nbiTiDSy+QCeL620
+REVAMLt8aTsHQ7Ror5sbDk=
=tYrn
-----END PGP SIGNATURE-----
More information about the Pythonmac-SIG
mailing list