Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86182
| Date | 2015-02-22 21:47 -0500 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: Unrecognized backslash escapes in string literals |
| References | <CAPTjJmqx3s1a0LL4RLgVB1PsOfyF9ryy6nwHwOwrQs1Zx2Hd-Q@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19044.1424659671.18130.python-list@python.org> (permalink) |
On 02/22/2015 09:29 PM, Chris Angelico wrote: > 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 > I've long thought they should be errors, but in Python they're not even warnings. It's one thing to let a user be sloppy on a shell's commandline, but in a program, if you have an invalid escape sequence, it should be an invalid string literal, full stop. And Python doesn't even treat these invalid sequences the same (broken) way C does. The documentation explicitly says it's different than C. If you're going to be different, at least be strict. -- DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Unrecognized backslash escapes in string literals Dave Angel <davea@davea.name> - 2015-02-22 21:47 -0500
csiph-web