unicode的Python3问题

我似乎无法在生产服务器上获得utf-8字符的unicode表示,尽管它在开发工作站上运行良好。

当我在Linux(Ubuntu服务器)上使用Python 3.6.9 [GCC 8.3.0]时。

>>> str('\u0394')
'\u0394'

>>>print('\u0394')               
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'latin-1' codec can't encode character '\u0394' in position 0: ordinal not in range(256)

当我在达尔文(Mac OS)上使用Python 3.6.5 [GCC 4.2.1]时

>>> str('\u0394')
'Δ'

>>> print('\u0394') 
Δ

By the look of it, I'd say that there is something broken on the ubuntu server as str() is suppose to convert to unicode in Python 3. However, it could well be that things work differently in revision 3.6.9 w.r.t. 3.6.5. Any tips on how could I get to the bottom of this?

评论
  • bipsam
    bipsam 回复
    print ('\u0394'.encode('utf8').decode('unicode-escape'))
    

    应该做的工作