Skip to content

Tutorial does not mention SyntaxWarning for invalid escape sequences #145642

@SnoopJ

Description

@SnoopJ

Documentation

NOTE: I am filing this issue on behalf of a user question in #python on the Libera IRC network, who was confused about the described discrepancy.

Part of the "Introduction" section of the official tutorial gives a demonstration of printing a Windows path that contains an invalid escape sequence and a newline. As given there, the user is told to expect a session like:

>>> print('C:\some\name')  # here \n means newline!
C:\some
ame

But since Python 3.12, the invalid escape sequence \s also produces a SyntaxWarning. In Python 3.14:

>>> print('C:\some\name')
<python-input-0>:1: SyntaxWarning: "\s" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\s"? A raw string is also an option.
C:\some
ame

To avoid confusing beginners, the tutorial should either simplify the path to only include the errant \n, or comment on the existence of the SyntaxWarning and mention that \s is an invalid sequence and is therefore passed through. The latter is probably preferable.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirtriagedThe issue has been accepted as valid by a triager.

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions