[Python-porting] Unclear error message

Mike Müller mmueller at python-academy.de
Wed Apr 26 12:59:24 EDT 2017


Am 26.04.17 um 17:23 schrieb Joe Stepansky:
> 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

This has nothing to do with open. The `\U....` specifies a certain Unicode
character, that does not exits. ;)

Solution:

On Windows, when copying and pasting paths always use raw strings starting with
an "r". So, this will solve your problem:

r'C:\Users\Joe\METAR.filelist.txt'

Mike

> 
>  
> 
> 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.
> 
>  
> 
> Joe
> 
> 
> 
> _______________________________________________
> Python-porting mailing list
> Python-porting at python.org
> https://mail.python.org/mailman/listinfo/python-porting
> 



More information about the Python-porting mailing list