Escape for str in Python

前端 未结 6 1458
星月不相逢
星月不相逢 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 03:14

    b is fine in the second example, you see two slashes because you're printing the representation of b, so slashes are escaped in it too.

    >>> b
    'tes\\ting'
    >>> print b
    tes\ting
    >>> 
    

提交回复
热议问题