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

小白问题,关于 python unicode。

  •  
  •   prefere · Sep 11, 2016 · 3464 views
    This topic created in 3669 days ago, the information mentioned may be changed or developed.

    # -*- coding:utf-8 -*- # python 2.7 windows IDLE symbol_u = "æ".decode("utf-8") print repr(symbol_u),u"\u00E6" >>u'\xe6' æ

    问题:

    符号 "æ" 的 unicode 值为 00E6 ,为什么 python 会解码为 u'\xe6' ?

    如果希望 python 解码为 u"\u00E6",要怎样作呢?

    5 replies  •  2016-09-17 02:50:12 +08:00
    loading
        1
    loading  
       Sep 11, 2016 via Android   ❤️ 1
    \x 是表示 16 进制, 00E6 和 e6 是一样的,就补 0 和大写的区别。
    loading
        2
    loading  
       Sep 11, 2016 via Android   ❤️ 1
    你用 type 看看,就知道了
    prefere
        3
    prefere  
    OP
       Sep 11, 2016
    @loading 直接拿正则替换吗?文本里有 n 多个这种字符,怕转错了。有别的方法吗?
    prefere
        4
    prefere  
    OP
       Sep 11, 2016
    @loading 明白了,谢谢。
    romanticbao
        5
    romanticbao  
       Sep 17, 2016
    搜索一下 “ python 编码”,一大堆结果。耐心看完几个就可以了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3663 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:13 · PVG 12:13 · LAX 21:13 · JFK 00:13
    ♥ Do have faith in what you're doing.