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

Python 原始字符串问题

  •  
  •   Delav · 2018-09-21 15:58:31 +08:00 · 1128 次点击
    这是一个创建于 2035 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Python 不使用手工加 r,可以把字符串转换为原始字符串吗? s = '[{"id":"","name":"","amount":"","ver":""}]' 不把这个字符串变为原始字符串的话,Python 默认对这个\转义就变成\这样了,再把这样的字符串发送出去,别的平台接受到的就变成'[{\"id\":\"\",\"name\":\"\",\"amount\":\"\",\"ver\":\"\"}]'这样了,有或者有什么办法让它原样发送出去吗

    Wincer
        1
    Wincer  
       2018-09-21 16:05:27 +08:00
    你把 s = '[{"id":"","name":"","amount":"","ver":""}]' 转成 JSON obj 再发出去不就可以了,为啥要发字符串出去
    Delav
        2
    Delav  
    OP
       2018-09-21 16:34:30 +08:00
    @Wincer 上面说错了,就是字符串是'[{\"id\":\"\",\"name\":\"\",\"amount\":\"\",\"ver\":\"\"}]'这样的,我又想把这个字符串原样发送出去(还是带有\的),怎么办?
    Wincer
        3
    Wincer  
       2018-09-21 17:41:47 +08:00
    @Delav
    ```
    >>> s = repr('[{\"id\":\"\",\"name\":\"\",\"amount\":\"\",\"ver\":\"\"}]')
    >>> s
    '\'[{"id":"","name":"","amount":"","ver":""}]\''
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3646 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:47 · PVG 12:47 · LAX 21:47 · JFK 00:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.