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

【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_第1张图片

【2】解决方案

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

1 #coding=utf-8

正常效果如下图:
python SyntaxError: Non-ASCII character '\xe6' in file_第2张图片

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

Good Good Study, Day Day Up.

顺序 选择 循环 总结

转载于:https://www.cnblogs.com/Braveliu/p/10570084.html

你可能感兴趣的:(python SyntaxError: Non-ASCII character '\xe6' in file)