推荐学习书目
› 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 · Jun 11, 2014 · 4374 views
    This topic created in 4488 days ago, the information mentioned may be changed or developed.
    在python中的字符串是“这是一个字符串”,但是一旦输入到了浏览器中就是/xe03之类的,
    已经尝试过
    1.reload(sys)
    sys.setdefaultencoding('utf-8')
    2.# -*- coding: utf-8 -*-

    均无法解决

    请问有什么办法能解决么?
    8 replies  •  2014-06-12 03:15:49 +08:00
    sujin190
        1
    sujin190  
       Jun 11, 2014
    json?
    alexapollo
        2
    alexapollo  
       Jun 11, 2014
    u'这是一个字符串'
    shinerene
        3
    shinerene  
    OP
       Jun 11, 2014
    @alexapollo 又尝试了一下 发现好像是存入到了list中的原因,如果直接给a赋值 ”你好“,浏览器出书还是”你好“ ,但是如果把a存入到了list中 再打印出来就是/xe03之类的了
    decken
        4
    decken  
       Jun 11, 2014
    @shinerene 在列表里面的存储方式应该是utf8的吧
    shinerene
        5
    shinerene  
    OP
       Jun 11, 2014
    @decken 对的 我不是很理解,比如说a=“你好” 在终端中a = '\xe4\xbd\xa0\xe5\xa5\xbd'
    但是print a就是你好。。。这是为什么呢。。
    alexapollo
        6
    alexapollo  
       Jun 11, 2014
    list的话要先做一下escape unicode
    yakczh
        7
    yakczh  
       Jun 11, 2014
    换python3 一劳永逸地解决编码问题,不用再折腾填坑了
    shinerene
        8
    shinerene  
    OP
       Jun 12, 2014
    @alexapollo 已经解决~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2491 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:10 · PVG 12:10 · LAX 21:10 · JFK 00:10
    ♥ Do have faith in what you're doing.