在Python脚本中,我们可能会输入一些中文。但由于Python脚本默认使用的是ASCII编码,所以中文字符无法表示。

  就会出现类似于以下这种错误:

File "/Users/lnphone/Desktop/test.py", line 3
SyntaxError: Non-ASCII character '\xe4' in file /Users/lnphone/Desktop/test.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

  解决这种问题的方法就是注明使用UTF-8编码,在脚本开头添加:

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

 

相关文章:

  • 2021-09-07
  • 2022-12-23
  • 2021-12-24
  • 2021-08-07
  • 2022-12-23
  • 2021-08-06
  • 2021-08-05
猜你喜欢
  • 2022-03-03
  • 2021-06-26
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2022-01-31
相关资源
相似解决方案