📜  python 部分打开文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:33.835000             🧑  作者: Mango

代码示例10
def read_in_chunks(file_object, chunk_size=1024):
    """Lazy function (generator) to read a file piece by piece.
    Default chunk size: 1k."""
    while True:
        data = file_object.read(chunk_size)
        if not data:
            break
        yield data


with open('really_big_file.dat') as f:
    for piece in read_in_chunks(f):
        process_data(piece)