[Python-Dev] Emit SyntaxWarning on unrecognized backslash escapes?

Chris Angelico rosuav at gmail.com
Tue Feb 24 00:53:11 CET 2015


On Tue, Feb 24, 2015 at 9:40 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Most don't, and cases like "\n" or "\t" in a Windows path name being
> converted to whitespace are utterly impossible to look up in an
> internet search when they fail, so a user learning on their own gets
> left with a broken program and no particularly effective ways to ask
> for help figuring it out.
>
> Like Unicode encoding errors they may appear a long way from the
> source of the offending data value (in this case, likely to be a file
> name copy and pasted from elsewhere on their system), and they don't
> give a particularly helpful error message (especially when the escape
> sequences are for whitespace).

And on the subject of Unicode errors, imagine a path name of
"C:\Users\YourName\Desktop\FileName.txt". Under Python 2, that'll work
fine; under Python 3, it'll fail with an error that, in all
probability, will be interpreted as "Unicode is hard :(" rather than
"loose backslash escapes are a problem".

ChrisA


More information about the Python-Dev mailing list