推荐学习书目
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 · Sep 21, 2018 · 1599 views
    This topic created in 2805 days ago, the information mentioned may be changed or developed.

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

    Wincer
        1
    Wincer  
       Sep 21, 2018
    你把 s = '[{"id":"","name":"","amount":"","ver":""}]' 转成 JSON obj 再发出去不就可以了,为啥要发字符串出去
    Delav
        2
    Delav  
    OP
       Sep 21, 2018
    @Wincer 上面说错了,就是字符串是'[{\"id\":\"\",\"name\":\"\",\"amount\":\"\",\"ver\":\"\"}]'这样的,我又想把这个字符串原样发送出去(还是带有\的),怎么办?
    Wincer
        3
    Wincer  
       Sep 21, 2018
    @Delav
    ```
    >>> s = repr('[{\"id\":\"\",\"name\":\"\",\"amount\":\"\",\"ver\":\"\"}]')
    >>> s
    '\'[{"id":"","name":"","amount":"","ver":""}]\''
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1379 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 23:57 · PVG 07:57 · LAX 16:57 · JFK 19:57
    ♥ Do have faith in what you're doing.