name="中{1}国" print(name) print(name.format("hah","hehe"))
写了一段代码,一运行就报错
File "F:\opensource\pythonDemo\src\test\Haha.py", line 24 SyntaxError: 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/