我不知道你收到这条消息的方式和地点,但看看这个例子:
$python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> txt = u'Dassault Myst\xe8re'
>>> txt
u'Dassault Myst\xe8re'
>>> print txt
Traceback (most recent call last):
File "", line 1, in
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 13:
ordinal not in range(128)
>>> ^D
$export LANG=en_US.UTF-8
$python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> txt = u'Dassault Myst\xe8re'
>>> txt
u'Dassault Myst\xe8re'
>>> print txt
Dassault Mystère
>>>^D
因此,您可以看到是否有一个控制台作为ASCII,然后在打印期间,有一个从unicode到ascii的转换,如果在ASCII范围外有字符,则抛出异常.
但是如果控制台可以接受unicode,那么一切都会正确显示.