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


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

Re: Unrecognized backslash escapes in string literals

Started byDave Angel <davea@davea.name>
First post2015-02-22 21:47 -0500
Last post2015-02-22 21:47 -0500
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Unrecognized backslash escapes in string literals Dave Angel <davea@davea.name> - 2015-02-22 21:47 -0500

#86182 — Re: Unrecognized backslash escapes in string literals

FromDave Angel <davea@davea.name>
Date2015-02-22 21:47 -0500
SubjectRe: Unrecognized backslash escapes in string literals
Message-ID<mailman.19044.1424659671.18130.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web