python script Non-ASCII character

Terry Reedy tjreedy at udel.edu
Sun Mar 19 16:01:54 EDT 2017


On 3/19/2017 1:38 PM, Xristos Xristoou wrote:
> hello i have create a python script when read some files using paths and do something with that files.
> if that paths for files is in english likes this "c:/my_path/english " then python script  working but if that paths is in my main language

Non-ascii in a pathname and non-ascii within a file are different 
issues.  On Windows, non-ascii in pathnames did not work consistently 
until 3.2 or maybe 3.3.

 > or the path have some blank character then not working

This should not be a problem.  With 2.7.13:

 >>> f = open('c:/program files/7-zip/readme.txt')
 >>> print(f.read())
7-Zip 9.20
----------
...

> SyntaxError: Non-ASCII character '\xce' in file Untitled_.py on line 15, but no encoding declared;

This is non-ascii within a file.

> can i fix that in python 2.7.13 ? can i find some solution to python read paths in my main language or paths with blanks?

Chris gave the answer for within-file non-ascii: provide the encoding.

-- 
Terry Jan Reedy



More information about the Python-list mailing list