[root@Debian 4test]#export LANG=zh_CN.UTF-8 [root@Debian 4test]#./test.py Traceback (most recent call last): File "./test.py", line 3, in <module> print u"\u5929" UnicodeEncodeError: 'ascii' codec can't encode character u'\u5929' in position 0: ordinal not in range(128) [root@Debian 4test]#
@billlee 没错我终端是 ssh 连接。然后编码如下 [root@Debian 4test]#locale -a locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_COLLATE to default locale: No such file or directory C C.UTF-8 POSIX en_US.utf8
我的终端是 mac 的 terminal 已经设置为支持中文的 GBK, UTF-8 等格式编码。能够显示中文。使用 ls 命令可以看到中文文件名称。也可输入。