>>> r'\'
File "<stdin>", line 1
r'\'
^
SyntaxError: EOL while scanning string literal
>>> r'\\'
'\\\\'
>>> r'\\\'
File "<stdin>", line 1
r'\\\'
^
SyntaxError: EOL while scanning string literal
파서가 원시 문자열의 백 슬래시를 일반 문자로 처리 할 수있는 것처럼 보이지만 (원시 문자열이 전부가 아닌가?) 분명한 것이 누락되었을 수 있습니다.
해결 방법
그 이유는 내가 굵게 강조한 부분에 설명되어 있습니다.
문자열 따옴표는 backslash, but the backslash remains in the string; for example,
r"\""
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 계속.
따라서 원시 문자열은 100 % 원시가 아니며 여전히 기본적인 백 슬래시 처리가 있습니다.
참조 페이지 https://stackoverflow.com/questions/647769
'파이썬' 카테고리의 다른 글
파이썬 변수가 앞에 오는 Python for-in 루프 (0) | 2020.09.30 |
---|---|
파이썬에서 대용량 텍스트 파일을 메모리에로드하지 않고 한 줄씩 읽을 수 있습니까? (0) | 2020.09.30 |
파이썬 문자열 대신 바이트로 작동하는 StringIO 대체? (0) | 2020.09.30 |
파이썬 장고 SUM 쿼리? (0) | 2020.09.30 |
파이썬 Python + MySQL-대량 삽입 (0) | 2020.09.30 |
댓글