我们在磁盘中有几个巨大的文件(大于RAM的大小).我想在python中逐行读取它们并在终端输出结果.我已经完成了[1]和[2],但我正在寻找不等到整个文件被读入内存的方法.
我将使用这两个命令:
cat fileName | python myScript1.py
python myScript2.py fileName
Run Code Online (Sandbox Code Playgroud)
with open("myfile.txt", "r") as myfile:
for line in myfile:
# do something with the current line
Run Code Online (Sandbox Code Playgroud)
要么
for line in sys.stdin:
# do something with the current line
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9524 次 |
最近记录: |