How do I automate the removal of all non-ascii characters from my code?

Jussi Piitulainen jpiitula at ling.helsinki.fi
Tue Sep 13 11:29:03 EDT 2011


Alec Taylor writes:

> Hmm, nothing mentioned so far works for me...
> 
> Here's a very small test case:
> 
> >>> python -u "Convert to Creole.py"
>   File "Convert to Creole.py", line 1
> SyntaxError: Non-ASCII character '\xe2' in file Convert to Creole.py
> on line 1, but no encoding declared; see
> http://www.python.org/peps/pep-0263.html for details
> >>> Exit Code: 1
> 
> Line 1: a=u'''≤'''.encode("ascii", "ignore").decode("ascii")

The people who told you to declare the source code encoding in the
source file would like to see Line 0.

See <http://www.python.org/peps/pep-0263.html>.

[1001] ruuvi$ cat ctc.py
# coding=utf-8
print u'''x ≤ 1'''.encode("ascii", "ignore").decode("ascii")
[1002] ruuvi$ python ctc.py
x  1
[1003] ruuvi$ 



More information about the Python-list mailing list