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

貌似遇到了字符编码的坑了。。

  •  
  •   shinerene ·
    Xiechen · 2014-06-11 19:53:09 +08:00 · 3241 次点击
    这是一个创建于 3578 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在python中的字符串是“这是一个字符串”,但是一旦输入到了浏览器中就是/xe03之类的,
    已经尝试过
    1.reload(sys)
    sys.setdefaultencoding('utf-8')
    2.# -*- coding: utf-8 -*-

    均无法解决

    请问有什么办法能解决么?
    8 条回复    2014-06-12 03:15:49 +08:00
    sujin190
        1
    sujin190  
       2014-06-11 20:07:06 +08:00
    json?
    alexapollo
        2
    alexapollo  
       2014-06-11 20:07:50 +08:00
    u'这是一个字符串'
    shinerene
        3
    shinerene  
    OP
       2014-06-11 20:27:25 +08:00
    @alexapollo 又尝试了一下 发现好像是存入到了list中的原因,如果直接给a赋值 ”你好“,浏览器出书还是”你好“ ,但是如果把a存入到了list中 再打印出来就是/xe03之类的了
    decken
        4
    decken  
       2014-06-11 21:01:12 +08:00
    @shinerene 在列表里面的存储方式应该是utf8的吧
    shinerene
        5
    shinerene  
    OP
       2014-06-11 21:04:03 +08:00
    @decken 对的 我不是很理解,比如说a=“你好” 在终端中a = '\xe4\xbd\xa0\xe5\xa5\xbd'
    但是print a就是你好。。。这是为什么呢。。
    alexapollo
        6
    alexapollo  
       2014-06-11 21:15:22 +08:00
    list的话要先做一下escape unicode
    yakczh
        7
    yakczh  
       2014-06-11 21:48:52 +08:00
    换python3 一劳永逸地解决编码问题,不用再折腾填坑了
    shinerene
        8
    shinerene  
    OP
       2014-06-12 03:15:49 +08:00
    @alexapollo 已经解决~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1944 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:23 · PVG 00:23 · LAX 09:23 · JFK 12:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.