shanghaipc 发表于 2017-4-24 11:39:16

Python Source Code Encodings

name="中{1}国"print(name)print(name.format("hah","hehe"))
  写了一段代码,一运行就报错
  File "F:\opensource\pythonDemo\src\test\Haha.py", line 24SyntaxError: Non-UTF-8 code starting with '\xd6' in file F:\opensource\pythonDemo\src\test\Haha.py on line 24, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
这是由于source编码引起的,在脚本开头设定编码即可。
  在文件第一行或者第二行设定
  #-*- coding:GBK -*-
运行就没问题了。
  参考地址:http://python.org/dev/peps/pep-0263/
页: [1]
查看完整版本: Python Source Code Encodings