def myreadlines(f, newline):
buf = ""
while True:
while newline in buf:
pos = buf.index(newline)
yield buf[:pos]
buf = buf[pos+len(newline):]
chunk = f.read(12)
if not chunk:
yield buf
break
buf += chunk
with open("file.txt") as f:
for line in myreadlines(f, "|"):
print(line)
python 读取大文件
最新推荐文章于 2024-07-12 19:06:42 发布