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

Isaac Morland ijmorlan at uwaterloo.ca
Tue Feb 24 21:56:17 CET 2015


On Tue, 24 Feb 2015, Ethan Furman wrote:

> On 02/24/2015 10:49 AM, Guido van Rossum wrote:
>> On Tue, Feb 24, 2015 at 10:47 AM, Ethan Furman wrote:
>>>
>>> I can attest from my impoverished Windows programming days that looking at
>>>
>>>   --> os.listdir('c:\temp')
>>>   SomeErrorMessage about syntax 'c:\temp'
>>>
>>> is not very helpful.  There is zero visual indication that the \ and the t
>>> are one character, not two.  Changing that error message to:
>>>
>>>   SomeErrorMessage about syntax 'c:[\t]emp'
>>>
>>> or
>>>
>>>   SomeErrorMessage about syntax 'c:\x07emp'
>>>
>>>     or something that shouts out, "hey!  one character in this 
>>> location!" would be a good thing.
>>
>> I like the \x07 solution.
>
> So final question is do we take the easy road and change the repr for 
> str to always use hex or unicode escapes instead of simple 
> backslash-escapes (and then run for our lives), or do we just hunt down 
> and change the appropriate error messages for files (and possibly re) ?

Just a data point from a random programmer:

I like the \x07 solution for the error message as it draws attention to 
the character at issue, but I also like to see \n, \t etc. in the result 
of repr because it is more readable for the common cases.

Isaac Morland           CSCF Web Guru
DC 2619, x36650         WWW Software Specialist


More information about the Python-Dev mailing list