SyntaxError: Non-ASCII character 'å' in file demo/demo.py on line 8, but no encoding declared;


环境配置

Python 3.5.3

问题描述

$ python demo/demo.py
  File "demo/demo.py", line 8
SyntaxError: Non-ASCII character '\xe5' in file demo/demo.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

解决方法

因为python的默认编码文件是ASCII,所以使用非英文字符会出现语法错误提示.

在源文件头部添加# coding=utf8 或者 # -*- coding:UTF-8 -*- 即可.

#!/usr/bin/env python3
# coding=utf8

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录