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

小白问题,关于 python unicode。

  •  
  •   prefere · 2016-09-11 08:51:35 +08:00 · 2453 次点击
    这是一个创建于 2777 天前的主题,其中的信息可能已经有所发展或是发生改变。

    # -*- 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 条回复    2016-09-17 02:50:12 +08:00
    loading
        1
    loading  
       2016-09-11 08:58:00 +08:00 via Android   ❤️ 1
    \x 是表示 16 进制, 00E6 和 e6 是一样的,就补 0 和大写的区别。
    loading
        2
    loading  
       2016-09-11 08:59:48 +08:00 via Android   ❤️ 1
    你用 type 看看,就知道了
    prefere
        3
    prefere  
    OP
       2016-09-11 09:01:15 +08:00
    @loading 直接拿正则替换吗?文本里有 n 多个这种字符,怕转错了。有别的方法吗?
    prefere
        4
    prefere  
    OP
       2016-09-11 09:06:17 +08:00
    @loading 明白了,谢谢。
    romanticbao
        5
    romanticbao  
       2016-09-17 02:50:12 +08:00
    搜索一下 “ python 编码”,一大堆结果。耐心看完几个就可以了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5437 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 01:36 · PVG 09:36 · LAX 18:36 · JFK 21:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.