推荐学习书目
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
decken
V2EX  ›  Python

python2.7 中一个奇怪的编码问题,麻烦大家帮忙看一下.

  •  
  •   decken ·
    DecKen · Apr 22, 2015 · 2678 views
    This topic created in 4073 days ago, the information mentioned may be changed or developed.
    gbk编码的字符串'say\xa1\xa1it\xa1\xa1right\xa4\xfdnow.wma'
    在windows下显示效果是这样的
    空格是全角空格
    在Linux下显示效果是这样的



    'say\xa1\xa1it\xa1\xa1right\xa4\xfdnow.wma'.decode("gbk")
    直接报解码错误

    去掉后面的\xa4\xf之后,可以正常解码
    'say\xa1\xa1it\xa1\xa1rightdnow.wma'.decode("gbk")

    现在的问题是是如何将其转换成正确的unicode?
    我就纳闷,同样是全角空格,怎么编码就不一样呢?
    5 replies    2015-04-22 18:55:42 +08:00
    lululau
        1
    lululau  
       Apr 22, 2015   ❤️ 1
    GBK 里没 \xa4\xfd 这个编码

    http://ff.163.com/newflyff/gbk-list/
    hahastudio
        2
    hahastudio  
       Apr 22, 2015   ❤️ 1
    gb18030 可以解码,但是显示的不对
    hahastudio
        3
    hahastudio  
       Apr 22, 2015   ❤️ 1
    Big5 里
    \xa4\xfd 对应 “王”
    decken
        4
    decken  
    OP
       Apr 22, 2015 via Android
    @lululau 奇怪的是在Win下却是显示成全角空格的
    vibbow
        5
    vibbow  
       Apr 22, 2015   ❤️ 1
    @decken Windows处理乱七八糟的编码问题估计已经处理习惯了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1569 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 16:29 · PVG 00:29 · LAX 09:29 · JFK 12:29
    ♥ Do have faith in what you're doing.