python SyntaxError: Non-ASCII character '\xe6' in file

时间:2023-11-24 13:05:20

【1】python程序执行报错

报错:SyntaxError: Non-ASCII character '\xe6' in file /tmp/788580473/main.py on line 7, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

现象如下图:

python SyntaxError: Non-ASCII character '\xe6' in file

【2】解决方案

经分析,属于编码问题(代码中含有中文),需要添加utf-8编码格式:

 #coding=utf-8

正常效果如下图:
python SyntaxError: Non-ASCII character '\xe6' in file

经验证,python2.0会报类似的错误,python3.0正常。

Good Good Study, Day Day Up.

顺序 选择 循环 总结