Pythonã®rawæåå(raw string)è¨æ³ã§ã¯ããã®æ«å°¾ãå¥æ°åã®ããã¯ã¹ã©ãã·ã¥(\
)ã¨ã§ããªããWindowsä¸ã®ãã©ã«ããã¹åã表ç¾ããã¨ããªã©ã§ç¹ã«æ³¨æã
# SyntaxError: EOL while scanning string literal ãçºç path_ng = r"C:\User\foobar\"
path_ok = r"C:\User\foobar" + "\\"
ãã¹åã®æååæä½ã§ããã°ãos.pathモジュールï¼日本語ï¼ãå©ç¨ããæ¹ãããã
Python 3.4, The Python Language Referenceãã該å½ç®æå¼ç¨ã
Even in a raw string, string quotes can be escaped with a backslash, but the backslash remains in the string; for example,
2. Lexical analysis - 2.4.1. String and Bytes literalsr"\""
is a valid string literal consisting of two characters: a backslash and a double quote;r"\"
is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the string, not as a line continuation.
é¢é£URL