read(), readline(), readlines()的区别和使用
read(), readline(), readlines()的区别
python中有神奇的三种读操作:read、readline和readlines
read():一次性读取整个文件内容。推荐使用read(size)方法,size越大运行时间越长
readline():每次读取一行内容。内存不够时使用,一般不太用
readlines():一次性读取整个文件内容,并按行返回到list,方便我们遍历
read(), readline(), readlines()的使用
with open("./result/vec.csv", "r") as f:
res = f.read()
print(res)
print("======================================")
with open("./result/vec.csv", "r") as f:
res = f.readline()
print(res)
print("======================================")
with open("./result/vec.csv", "r") as f:
res = f.readlines()
print(res)