[英]SyntaxError: Non-ASCII character '\xe2' by just copying to another project
I got this error after copying the content to another project:将内容复制到另一个项目后出现此错误:
SyntaxError: Non-ASCII character '\xe2' in file ***/PostToIn.py on line 81, but no encoding declared;
see http://python.org/dev/peps/pep-0263/ for details
The content's code is:内容的代码是:
exp = "9 √ 3 ="
This SyntaxError still popped up even though I commented this line as the following:即使我将此行注释为以下内容,此 SyntaxError 仍然弹出:
# exp = "9 √ 3 ="
But the same line in the original project could run smoothly without any error.但是原来项目中的同一行可以顺利运行,没有任何错误。
What's the matter, please?请问怎么回事?
Thanks a lot!非常感谢!
The string you have there has a non-ascii character √
which python can't parse.你在那里的字符串有一个非 ascii 字符√
,python 无法解析。 The solution is to replace it with \\xe2
which will then expand to √
when the code runs.解决方案是用\\xe2
替换它,然后在代码运行时将其扩展为√
。 So the fixed code should look like this:所以固定代码应该是这样的:
exp = u"9 \xe2 3 ="
The other solution is to tell python the string you have is actually UTF-8 by prefixing it with a u.另一个解决方案是通过在它前面加上 u 来告诉 python 你拥有的字符串实际上是 UTF-8。
exp = u"9 √ 3 ="
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.