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
kidlfy
V2EX  ›  Python

python2 编码设置 sys

  •  
  •   kidlfy · 2018-09-14 10:58:11 +08:00 · 1362 次点击
    这是一个创建于 2043 天前的主题,其中的信息可能已经有所发展或是发生改变。

    coding: utf-8

    import sys reload(sys) sys.setdefaultencoding('utf8')

    为什么 setdefaultencoding 飘黄,没有这个方法

    5 条回复    2018-09-14 16:40:06 +08:00
    mcoo1997
        1
    mcoo1997  
       2018-09-14 14:55:19 +08:00 via Android
    pycharm 的提示么 能运行就别管
    holajamc
        2
    holajamc  
       2018-09-14 16:18:15 +08:00
    虽然在 python2 中这可以解决部分编码问题,但十分不建议这样操作)
    kidlfy
        3
    kidlfy  
    OP
       2018-09-14 16:32:38 +08:00
    @mcoo1997 但是没有用啊,还是报编码错误
    kidlfy
        4
    kidlfy  
    OP
       2018-09-14 16:34:01 +08:00
    @holajamc 虽然知道但是在 mysql 导成 excel 时,save 的时候总是报编码错误,mysql 导出的数据中含有中文,设置了 charset=utf8 也没用
    mcoo1997
        5
    mcoo1997  
       2018-09-14 16:40:06 +08:00 via Android
    @kidlfy csv 有 unicode-csv 你看看 xls 有没有类似的库
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1940 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:18 · PVG 00:18 · LAX 09:18 · JFK 12:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.