How to prevent automatic escaping of special characters in Python

前端 未结 2 1751
野性不改
野性不改 2020-12-06 18:07

I\'m writing a Python script that accepts file paths as strings, parses them, appends a command name, and builds a list, which is then passed to subprocess.Popen()

2条回答
  •  广开言路
    2020-12-06 18:43

    You can create a raw string by prepending r to the string literal notation

    r"hello\nworld"
    

    becomes

    "hello\\nworld"
    

    You can read some more here

提交回复
热议问题