|  |      1zxc111      2013-01-25 18:33:54 +08:00 append时先decode('gb2312') 输出时encode回来就好了 | 
|  |      2reusFork      2013-01-25 19:02:09 +08:00 自己写个打印函数就行,例如 http://gist.github.com/4633523 | 
|  |      3justfly OP @zxc111 没用 UnicodeEncodeError: 'ascii' codec can't encode character u'\u87d2' in position 0: ordinal not in range(128) | 
|      5013231      2013-01-25 20:33:47 +08:00 這跟編碼沒關係, 存入list不會轉換unicode的編碼 -- 事實上根本不用考慮unicode的編碼, 只有str存在編碼問題. 你直接存進mongodb就行了. 關於python中文字編碼問題請看這個帖子: http://www.v2ex.com/t/35110 | 
|  |      6justfly OP @013231 我要先写入文件,可是json.dumps(我构造的dict)之后,写入文件也是这些东西啊,我就想让他在文件里显示出中文,怎么就这么难。一堆 {"gloss": ["\u6c7d\u8f66\uff0c\u8f7f\u8f66", "\u540a\u8231\uff0c\u98de\u8239\u540a\u8231", "\u8f66\u53a2\uff0c\u706b\u8f66\u8f66\u53a2", "\u6709\u8f68\u7535\u8f66\uff0c\u7535\u8f66", "\u5347\u964d\u53a2\uff0c\u7535\u68af", "\u6218\u8f66", "\u8f66\uff0c\u8f66\u8f86\uff0c\u6709\u8f6e\u7684\u8f66", "\u8fd0\u8d27\u9a6c\u8f66", "\u51ef\u65cb\u95e8", "\u540a\u7bee", "\u8f66\u76ae", "\u6c14\u7403", "\u5ba2\u8f66"], "word": "python"} | 
|  |      7wwqgtxx      2013-01-25 21:06:06 +08:00 via Android 用python3.3试试,可能会解决你的问题 | 
|      8013231      2013-01-25 21:25:50 +08:00 @justfly 首先, json中使用轉義寫法是完全符合規範的(http://www.ietf.org/rfc/rfc4627.txt). 如果你想以不轉義的方式寫入json, 可以這樣: http://gist.github.com/4634405 |