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

Joao S. O. Bueno jsbueno at python.org.br
Tue Feb 24 13:00:53 CET 2015


On 23 February 2015 at 18:39, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Serhiy Storchaka wrote:
>>
>> The problem is that the user don't know that he should read the
>> documentation. It just find that his script works with "C:\sample.txt", but
>> doesn't work with "D:\test.txt". He has no ideas what happen.
>
>
> Even with the syntax error, there are filenames that
> will mysteriously fail, e.g. "C:\ninjamoves.txt".


That is the reason I urge folks to think about the root cause,
and check if this proposal is the best way to tackle it:
The failing cases are the ones that won't be affected by this change at all -
as they are valid escaped strings!

There will be no error for
c:\tmp\myfile.txt - it will ever be just "file not found" - unless the
warning comes to
using "\" as file path separator (and no, I don  think just doing that
would properly
address the issue as well).

Could we just use Guido's time machine and go back to the point in time where
some MS head decided to go with "\" instead of "/", and deliver a well
placed punch? :-)

Or maybe have IOError for "file not found" to get some fuzzy logic and
display a more verbose error message if there are "\n"s and "\t"s on
the filename
and platform is Windows?  I think that  could go along the proposal for
deprecating non-escaping "\<x>" sequences .

By the way,  although I am writing to get the root issue covered, I think
deprecating them would be a good thing, yes. Despite my previous comment
on deprecating code that works, on a deeper though it _is_ worth the issue.

  js
 -><-



>
> --
> Greg
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/jsbueno%40python.org.br


More information about the Python-Dev mailing list