开发环境:eclipse3.2.1+PyDev
代码:
def buildConnectionString(params):
"""this is the second example for python是很出色的开源编程语言.
Returns string."""
return ";".join(["%s=%s" % (k, v) for k, v in params.items()])
if __name__ == "__main__":
myParams = {"server":"192.168.1.16", \
"database":"KYES1", \
"uid":"sa", \
"pwd":"xian" \
}
print buildConnectionString(myParams)
运行结果:
SyntaxError: Non-ASCII character '\xe6' in file D:\work\aa\src\d\two.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
原因:
doc string有中文
解决:
#coding=GB2312
再次运行结果:
pwd=xian;database=KYES1;uid=sa;server=192.168.1.16
代码:
def buildConnectionString(params):
"""this is the second example for python是很出色的开源编程语言.
Returns string."""
return ";".join(["%s=%s" % (k, v) for k, v in params.items()])
if __name__ == "__main__":
myParams = {"server":"192.168.1.16", \
"database":"KYES1", \
"uid":"sa", \
"pwd":"xian" \
}
print buildConnectionString(myParams)
运行结果:
SyntaxError: Non-ASCII character '\xe6' in file D:\work\aa\src\d\two.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
原因:
doc string有中文
解决:
#coding=GB2312
再次运行结果:
pwd=xian;database=KYES1;uid=sa;server=192.168.1.16
本文介绍了一个关于Python脚本中出现的非ASCII字符错误,并提供了解决方案。通过声明正确的文件编码,成功解决了因中文注释导致的语法错误。
443

被折叠的 条评论
为什么被折叠?



