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


Groups > comp.lang.python > #86178 > unrolled thread

Unrecognized backslash escapes in string literals

Started byChris Angelico <rosuav@gmail.com>
First post2015-02-23 13:29 +1100
Last post2015-02-23 13:29 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#86178 — Unrecognized backslash escapes in string literals

FromChris Angelico <rosuav@gmail.com>
Date2015-02-23 13:29 +1100
SubjectUnrecognized backslash escapes in string literals
Message-ID<mailman.19041.1424658578.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web