Escape for str in Python

前端 未结 6 1448
星月不相逢
星月不相逢 2021-01-25 02:45

Wow, this should be so simple, but it\' just not working. I need to inset a \"\\\" into a string (for a Bash command), but escaping just doesn\'t work.

>>&         


        
6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-25 02:58

    You are being misled by Python's output. Try:

    >>> a = "test\\ing"
    >>> print(a)
    test\ing
    >>> print(repr(a))
    'test\\ing'
    >>> a
    'test\\ing'
    

提交回复
热议问题