python学习笔记-错误与解法
《python程序设计基础与应用》书p.18613.2.1(1)错误情况:SyntaxError: multiple statements found while compiling a single statementSyntaxError:编译单个语句时发现多个语句获得乱码原因:编码问题解法:将请求的类文件读取再解码decode(‘utf-8’)```pythonimpo...
·
《python程序设计基础与应用》书p.186
13.2.1(1)
错误情况:
SyntaxError: multiple statements found while compiling a single statement
SyntaxError:编译单个语句时发现多个语句
奇怪点如下
代码:
import urllib.request
fp=urllib.request.urlopen(r'http://www.python.org')
print(fp.read(100))
print(fp.read(100).decode())
fp.close()
结果:
删除decode(),结果同上。
再删除read(100)里的100:
import urllib.request
fp=urllib.request.urlopen(r'http://www.python.org')
print(fp.read())
print(fp.read())
fp.close()
结果:
发现行数变多了,无格式。
另一种代码:
import urllib.request
response = urllib.request.urlopen('http://python.org/')
result = response.read().decode()
print(result)
示例结果:
我的结果:
未编码结果:
更多推荐
已为社区贡献1条内容
所有评论(0)