SyntaxError: Non-ASCII character 'xc4' in file newYear.py on line 6, but no encoding declared;

xiaoxiao2021-02-28  33

SyntaxError: Non-ASCII character '\xc4' in file newYear.py on line 6, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

这是因为文件中有中文字符,而文件没有指定编码方式。

文件开头添加以下代码:

一、在文件头部添加如下注释码:

 # coding=<encoding name> 例如,可添加# coding=utf-8

二、在文件头部添加如下两行注释码:

#!/usr/bin/python

# -*- coding: <encoding name> -*- 例如,可添加# -*- coding: utf-8 -*-

三、在文件头部添加如下两行注释码:

 #!/usr/bin/python

# vim: set fileencoding=<encoding name> : 例如,可添加# vim: set fileencoding=utf-8 :

四、

 #encoding:utf-8

五、

# -*- coding: cp936 -*-

# -*- coding: utf-8 -*-

转载请注明原文地址: https://www.6miu.com/read-2399995.html

最新回复(0)