python打印列表中的中文_Python -- List 打印中文内容

Python 的 List 如果有中文的話, 會印出 \xe4\xb8... 等等的編碼, 要如何印出中文呢(如下範例)? (Debug 方便查看)

>>> a = ['中文', 'ab']

>>> print a

['\xe4\xb8\xad\xe6\x96\x87', 'ab']

Python 的 List 要印出 中文 編碼

下述列出幾種作法:

>>> a = ['中文', 'ab']

>>> print a

['\xe4\xb8\xad\xe6\x96\x87', 'ab']

>>> print str(a).decode('string_escape')

['中文', 'ab']

使用 uniout 來達成

安裝: sudo pip install uniout # Source code:https://github.com/moskytw/uniout

>>> a = ['中文', 'ab']

>>> import uniout

>>> print a

['中文', 'ab']

直接取用 _uniout 來達成

從上述 uniout Project 直接取用 _uniout.py

>>> a = ['中文', 'ab']

>>> import _uniout

>>> print _uniout.unescape(str(a), 'utf8')

['中文', 'ab']

相關網頁

==================================================

以下是自己实践的内容,转换后会变成str,

aaa = str(AirConditions).decode('string_escape')

print aaa

print len(AirConditions)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值