W1401 anomalous-backslash-in-string

Message

"Anomalous backslash in string: '%s'. String constant might be missing an r prefix."

Description

Used when a backslash is in a literal string but not as an escape.

Example

In the following examle the string that is assigned to bad has a bad backslash sequence (\s). The string good is marked as a raw string (r prefix). In also_good the backslash before s is escaped.

def example():
    bad = "String with \some backslash"
    good = r"String with \some backslash"
    also_good = "String with \\some backslash"
2:12: W1401: Anomalous backslash in string: '\s'. String constant might be missing an r prefix.

Some of the supported backslash sequences are \n for newline, \t for a tab and \\ for a backslash. See the python docs. for the full list.

Running Pylint locally? In your CI?

There is a better way! Run PyCodeQual & get Pylint findings with history, diffs and statistics.

Click here to find out more.