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

"abc"转 b"abc",这样 string 直接转 byte, python 有没有方法?

  •  
  •   nicegoing · 2016-10-31 18:23:47 +08:00 · 4697 次点击
    这是一个创建于 2705 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我 google 下,都是 string 如何转 byte 的,请问如果简单的实现该功能。
    9 条回复    2016-11-22 09:08:50 +08:00
    lll9p
        1
    lll9p  
       2016-10-31 18:59:05 +08:00 via Android
    eval 么 😂
    ethego
        2
    ethego  
       2016-10-31 19:00:32 +08:00
    bytearray()
    Mark3K
        3
    Mark3K  
       2016-10-31 19:01:19 +08:00
    In [2]: x.encode("utf-8")
    Out[2]: b'abc'
    soratadori
        4
    soratadori  
       2016-10-31 19:01:51 +08:00
    a = "abcdefg 你好"
    b = a.encode()
    print(b)
    Lonely
        5
    Lonely  
       2016-10-31 19:02:59 +08:00
    楼上都说了
    suixn
        6
    suixn  
       2016-10-31 19:22:31 +08:00
    encode
    nicegoing
        7
    nicegoing  
    OP
       2016-10-31 19:40:10 +08:00 via iPhone
    好吧.我傻了.被编码解码搞糊涂了
    GreatMartial
        8
    GreatMartial  
       2016-10-31 21:25:38 +08:00 via Android
    我也容易记反
    zungmou
        9
    zungmou  
       2016-11-22 09:08:50 +08:00 via iPhone
    @GreatMartial 总是容易把 encode 记做编码为某种字符编码的字符串。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5167 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 09:30 · PVG 17:30 · LAX 02:30 · JFK 05:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.