Python source编码设定

来源:互联网 发布:刺客信条袖剑淘宝网 编辑:程序博客网 时间:2024/06/09 15:54

用python编写代码的时候遇到问题,运行报错:

import urllib.request google= urllib.request.urlopen('http://www.google.com')  print('http header:\n', google.info())  print('http status:', google.getcode()) print('url:', google.geturl())  for line in google: # 就像在操作本地文件     print(line)  google.close()  

SyntaxError: Non-UTF-8 code starting with '\xbe' in file E:\code\PythonTest\src\test\__init__.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263for details


这是由于source编码引起的,在脚本开头设定编码即可。

在文件第一行或者第二行设定</p>#-*- coding:GBK -*-

运行就正确了

0 0
原创粉丝点击