嗨喽~大家好呀,这里是魔王呐 ❤ ~!
python更多源码/资料/解答/教程等 点击此处跳转文末名片免费获取
1.行遍历实现
在python中如果要将一个文件完全加载到内存中,通过file.readlines()即可,
但是在文件占用较高时,我们是无法完整的将文件加载到内存中的,
这时候就需要用到python的file.readline()进行迭代式的逐行读取:
filename = 'hello.txt'
with open(filename, 'r') as file:
line = file.readline()
counts = 1
while line:
if counts >= 50000000:
break
line = file