read 读取整个文件,readline 一次读取一行,readlines 读取整个文件到一个list中,配合遍历for循环使用,可以看到readlines 和read的区别,readlines每一行后面都有‘\n’
![](https://img.haomeiwen.com/i8651443/7afcbc36f9c9d393.png)
![](https://img.haomeiwen.com/i8651443/906717a6e3b72ac0.png)
![](https://img.haomeiwen.com/i8651443/7f0e27c1fdc3d6ce.png)
配合for循环使用,以及更规范的写法:
![](https://img.haomeiwen.com/i8651443/3b6fd882086be5c1.png)
但是使用request模块时,使用read较方便
from urllib import request
url='http://bills.mugglecode.com/sample.html'
geturl=request.urlopen(url)
print(geturl.read())
网友评论