Python Source Code Encodings

来源:互联网 发布:淘宝如何一元秒杀 编辑:程序博客网 时间:2024/05/17 03:44
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/