[Python-porting] Unclear error message

David Malcolm dmalcolm at redhat.com
Wed Apr 26 12:43:14 EDT 2017


On Wed, 2017-04-26 at 11:23 -0400, Joe Stepansky wrote:
> I’ve decided to just jump into 3.6 by porting one of my Python 2.7
> programs. The first error I received was an easy one to resolve, but
> now I have one I don’t understand. Here’s the code:
>  
> with open(‘C:\Users\Joe\METAR.filelist.txt’,’r’) as METAR_filelist:
>               ^
> This gives me an error message with a “caret” below the first (open)
> parentheses and the following message:
>  
> SyntaxError: (Unicode error) ‘unicodeescape’ codec can’t decode bytes
> in position 2-3: truncated \UXXXXXXXX escape
>  
> Huh? I tried removing the parentheses but, of course, that was also a
> syntax error. Checked the online 3.6 docs for “with open” and my code
> looks OK. But it isn’t. Any suggestions welcome.

The backslash in the path is being interpreted by Python as the first
part of an escape sequence, and "\U" has special meaning.

Have a look at:
http://stackoverflow.com/questions/12953683/backslashes-in-windows-file
path

for some ideas for workarounds.


Dave




More information about the Python-porting mailing list