怎么解决syntaxerror:non-utf-8 code starting with \xc4'in file
首行增加,已测试可用。
# coding=gbk
程序中出现中文,运行的时候出现如下错误:
![](https://gss0.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D600%2C800/sign=9cc51c47befb43161a4a727c10946a1b/faedab64034f78f0569ee67f75310a55b2191ca0.jpg)
SyntaxError: Non-UTF-8 code starting with 'xc1' in file C:...xxx.py on line 8, but no encoding declared; see
http://python.org/dev/peps/pep-0263/ for details
导致出错的根源就是编码问题。
解决方案是:
在程序最上面加上:
![](https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D600%2C800/sign=ca26308d0655b3199cac8a737399ae1e/241f95cad1c8a786acf236826b09c93d71cf5065.jpg)
# coding=gbk
这样程序就可以正常运行了