V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ivito
V2EX  ›  Python

使用 xlrd 模块读取 excel 中汉字 l 时编码问题

  •  
  •   ivito ·
    fireboyvt · 2014-12-22 14:00:06 +08:00 · 5693 次点击
    这是一个创建于 3425 天前的主题,其中的信息可能已经有所发展或是发生改变。
    文件开始设置编码格式
    # -*- coding: utf-8 -*-
    读取excel中的某一列元素print时,会直接显示汉字的unicode编码
    wb = open_workbook(docname);
    table = wb.sheet_by_index(0);
    col = self.table.col_values(0);
    print col;
    而如果只读取某个单元格后print则能显示汉字
    col = self.table.col_values(1)[8];
    print col;
    为什么读取整列就不能显示汉字呢
    2 条回复    2014-12-23 12:22:12 +08:00
    likaci
        1
    likaci  
       2014-12-22 15:33:09 +08:00
    太巧了,前天刚遇到这个问题
    ---
    这个和xlrd无关,读取的数据是存储在list中的。
    python2 list中的汉字没法直接打印

    http://blog.longwin.com.tw/2014/09/python-list-print-chinese-2014/
    ivito
        2
    ivito  
    OP
       2014-12-23 12:22:12 +08:00
    @likaci 靠谱,list中的中文直接打印会打印出unicode编码,如果单独打印list中的某一个元素可以打印出中文
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1030 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 21:19 · PVG 05:19 · LAX 14:19 · JFK 17:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.