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

如何 16 进制转义

  •  
  •   saximi · 2017-08-17 22:05:10 +08:00 · 2308 次点击
    这是一个创建于 2445 天前的主题,其中的信息可能已经有所发展或是发生改变。
    非 ASCII Unicode 字符可以以十六进制转移(\xNN )编写到一个字符串中。
    请问程序如何写呢?
    谢谢
    4 条回复    2017-08-18 15:57:34 +08:00
    izoabr
        1
    izoabr  
       2017-08-17 22:26:26 +08:00
    就这么写
    ysc3839
        2
    ysc3839  
       2017-08-18 00:49:23 +08:00 via Android
    你的意思是,有一段\x 转义的字符串,你要转换成 bytes?
    NoAnyLove
        3
    NoAnyLove  
       2017-08-18 08:20:12 +08:00
    完全不知道在说什么,Orz,我猜是这个意思?

    ```python3
    s = "Hello\n 中文\nWorld"
    ss = ''.join('\\x%02X' % b for b in s.encode('utf-8'))
    print(ss)
    ```
    860670496
        4
    860670496  
       2017-08-18 15:57:34 +08:00
    当然用键盘直接敲\xNN 啊……对,不要用马克笔往屏幕上画
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3315 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.