本文轉自:http://blog.longwin.com.tw/2014/09/python-list-print-chinese-2014/html
Python 的 List 若是有中文的話, 會印出 \xe4\xb8... 等等的編碼, 要如何印出中文呢(以下範例)? (Debug 方便查看)python
>>> a = ['中文', 'ab'] >>> print a ['\xe4\xb8\xad\xe6\x96\x87', 'ab']
下述列出幾種做法:git
使用 decode('string_escape') 來達成github
>>> a = ['中文', 'ab'] >>> print a ['\xe4\xb8\xad\xe6\x96\x87', 'ab'] >>> print str(a).decode('string_escape') ['中文', 'ab']
安裝: sudo pip install uniout # Source code:https://github.com/moskytw/unioutspa
>>> a = ['中文', 'ab'] >>> import uniout >>> print a ['中文', 'ab']
從上述 uniout Project 直接取用 _uniout.pycode
>>> a = ['中文', 'ab'] >>> import _uniout >>> print _uniout.unescape(str(a), 'utf8') ['中文', 'ab']
==================================================htm
如下是本身實踐的內容,轉換後會變成str,blog
aaa = str(AirConditions).decode('string_escape') print aaa print len(AirConditions)