SyntaxError: Non-ASCII character ‘\xe6‘ in file E:/pythondemo/example2.py on line 2, but no encoding

简介: SyntaxError: Non-ASCII character ‘\xe6‘ in file E:/pythondemo/example2.py on line 2, but no encoding

原因


这个错误主要是由于python2的编码默认是ASCII,你的文件里有中文就必须要用utf-8编码


解决


在文件需要在文件开头标注:


#coding=utf-8


再运行就OK了。

相关文章
|
4月前
|
编解码 开发者 Python
【Python】已解决:UnicodeEncodeError: ‘gbk’ codec can’t encode character ‘\u0157’ in position 1: illegal m
【Python】已解决:UnicodeEncodeError: ‘gbk’ codec can’t encode character ‘\u0157’ in position 1: illegal m
57 1
|
4月前
|
编解码 程序员 开发者
【Python】已解决:UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xa1 in position 0: invalid start by
【Python】已解决:UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xa1 in position 0: invalid start by
3528 0
|
4月前
|
编解码 开发者 Python
【Python】已解决:UnicodeEncodeError: ‘utf-8’ codec can’t encode characters in position 42-43: surrogates
【Python】已解决:UnicodeEncodeError: ‘utf-8’ codec can’t encode characters in position 42-43: surrogates
403 0
|
4月前
|
编解码 开发者 Python
【Python】已解决:SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: t
【Python】已解决:SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: t
465 0
|
6月前
|
编解码 Python Windows
Python写入文件报错‘gbk’ codec can’t encode character的解决办法
Python写入文件报错‘gbk’ codec can’t encode character的解决办法
192 2
|
6月前
|
编解码 Python Windows
Python文件路径报错SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: t
Python文件路径报错SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: t
|
XML 编解码 数据格式
python报错 ‘utf-8‘ codec can‘t encode characters in position xxxx-xxxx: surrogates not allowed
python报错 ‘utf-8‘ codec can‘t encode characters in position xxxx-xxxx: surrogates not allowed
465 0
|
前端开发
CSS安装出错:Unicode Character Check -> Your temp directory path contains Unicode characters........
CSS安装出错:Unicode Character Check -> Your temp directory path contains Unicode characters........
488 0
Python编码错误的解决办法SyntaxError: Non-ASCII character '\xe7' in file
Python编码错误的解决办法SyntaxError: Non-ASCII character '\xe7' in file