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

请教一个 encode 方法的问题

  •  
  •   saximi · Aug 15, 2017 · 2050 views
    This topic created in 3218 days ago, the information mentioned may be changed or developed.
    已知 UNICODE 码制下,十六进制值 OxCD 和 OxE8 分别对应这两个特殊字符“Ä”、“è”
    >>> S='Äè'
    >>> S.encode('latin-1')
    b'\xc4\xe8'

    上面程序的输出为何将这两个字符显示为十六进制格式?与之相比,下面的程序输出就是 ASCII 字符而不是十六进制格式,这是为何?
    >>> S='spam'
    >>> S.encode('latin-1')
    b'spam'

    恳请指点,谢谢!
    3 replies    2017-08-16 09:28:44 +08:00
    Librazy
        1
    Librazy  
       Aug 16, 2017
    boboliu
        2
    boboliu  
       Aug 16, 2017 via Android
    建议仔细阅读 docs.python.org ,不要欺负楼上一个没写过 Python 的来给初学 Python 的查资料了 233 XD
    NoAnyLove
        3
    NoAnyLove  
       Aug 16, 2017
    encode 之后当然就是 bytes 了啊,不能在 ASCII 范围内显示的字符(包括 0~127 之间的不可见字符),就被表示成 16 进制咯
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5794 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 01:44 · PVG 09:44 · LAX 18:44 · JFK 21:44
    ♥ Do have faith in what you're doing.