Escape for str in Python

前端 未结 6 1457
星月不相逢
星月不相逢 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:06

    If you want double slashes because the shell will escape \ again, use a raw string:

    b = a[:3] + r'\\' + a[3:]
    

提交回复
热议问题