Sublime Forum

Python, escape character thwarts triple quotes

#1

In Python, the escape back slash is saving that character from the triple quote commenting.

0 Likes

#2

According to the Python documentation on String and Byte literals:

In plain English: Both types of literals can be enclosed in matching single quotes ( ' ) or double quotes ( " ). They can also be enclosed in matching groups of three single or double quotes (these are generally referred to as triple-quoted strings ). The backslash ( \ ) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

[snip]

In triple-quoted literals, unescaped newlines and quotes are allowed (and are retained), except that three unescaped quotes in a row terminate the literal. (A “quote” is the character used to open the literal, i.e. either ' or " .)

Unless an 'r' or 'R' prefix is present, escape sequences in string and bytes literals are interpreted according to rules similar to those used by Standard C. The recognized escape sequences are:

It doesn’t say that escape sequences aren’t allowed in triple quoted strings, but it does say that you need to prefix a string constant with r or R if you want it to not interpret escape characters.

As such, it seems like the syntax highlighting is working as expected here.

0 Likes