python 读取excel 内的中文显示为unicode 编码
生活随笔
收集整理的這篇文章主要介紹了
python 读取excel 内的中文显示为unicode 编码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
測試的excel 顯示如下
讀取excel 打印的效果如下
?現在想顯示為中文
處理代碼如下
#!/usr/bin/python#
# -*- coding: utf-8 -*-
import xlrd
import sys
reload(sys)
sys.setdefaultencoding("utf-8")book = xlrd.open_workbook('/home/hly/hly/test.xls')
sheet = book.sheet_by_index(1)
rows = sheet.nrows
content_list = []
for i in range(rows):content_list.append(sheet.row_values(i))# 處理list中文亂碼
case_list = str(content_list).replace('u\'', '\'').decode("unicode-escape")
print (case_list)
打印的效果如下
中文顯示了
python 2x 中文有亂碼問題, python 3x 沒有
?
總結
以上是生活随笔為你收集整理的python 读取excel 内的中文显示为unicode 编码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小狗狗回来就上吐下泻,狗狗上吐下泻能自愈
- 下一篇: 微信个性签名乐观