Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86178

Unrecognized backslash escapes in string literals

Date 2015-02-23 13:29 +1100
Subject Unrecognized backslash escapes in string literals
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.19041.1424658578.18130.python-list@python.org> (permalink)

Show all headers | View raw


In Python, unrecognized escape sequences are treated literally,
without (as far as I can tell) any sort of warning or anything. This
can mask bugs, especially when Windows path names are used:

>>> 'C:\sqlite\Beginner.db'
'C:\\sqlite\\Beginner.db'
>>> 'c:\sqlite\beginner.db'
'c:\\sqlite\x08eginner.db'

To a typical Windows user, the two strings should be equivalent - case
insensitive file names, who cares whether you say "Beginner" or
"beginner"? But to Python, one of them will happen to work, the other
will fail badly.

Why is it that Python interprets them this way, and doesn't even give
a warning? What happened to errors not passing silently? Or, looking
at this the other way: Is there a way to enable such warnings/errors?
I can't see one in 'python[3] -h', but if there's some way elsewhere,
that would be a useful thing to recommend to people (I already
recommend running Python 2 with -tt).

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Unrecognized backslash escapes in string literals Chris Angelico <rosuav@gmail.com> - 2015-02-23 13:29 +1100

csiph-web