码迷,mamicode.com
首页 > 其他好文 > 详细

read,readline,readlines的特点与区别

时间:2019-10-03 12:33:47      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:encoding   test   utf8   type   inf   open   技术   enc   odi   

1.read

  • 读取全部文件
with open("test.text", "r",encoding='utf8') as f:
    print(f.read())

输出:
技术图片

2.readline

  • 读取下一行
with open("test.text", "r",encoding='utf8') as f:
    # print(f.read())
    for i in range(10):
        print(f.readline())

输出:
技术图片

3.readlines

  • 读取全部,并返回一个列表
with open("test.text", "r",encoding='utf8') as f:
    print(f.readlines(), type(f.readlines()))

输出:
技术图片

read,readline,readlines的特点与区别

标签:encoding   test   utf8   type   inf   open   技术   enc   odi   

原文地址:https://www.cnblogs.com/bigox/p/11619297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!