python入门,hhh

在慕课网上学习python入门,编写汉诺塔的递归调用时,代码正确。但是加上注释后编译不通过

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

报如下错误:

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

原因如下:

Python默认是以ASCII作为编码方式的,如果在自己的Python源码中包含了中文(或者其他非英语系的语言),此时即使你把自己编写的Python源文件以UTF-8格式保存了,但实际上,这依然是不行的。

解决方法:

第一行加上如下代码

# -*- coding: UTF-8 -*- 

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

 

相关文章:

  • 2021-09-25
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-06-25
  • 2022-01-03
  • 2021-10-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案