728x90
반응형
from functools import partial

def chunked_file(fp, block_size=1024 * 1024 * 50): # 50MB
    return [chunk for chunk in iter(partial(fp.read, block_size), '')]      
        
def read_file(file_path):
    with open(file_path) as f_read:
        return chunked_file(f_read)
        
        
# 사용방법        
file_path = "/data/large_file.txt"
for content in read_file(file_path):
	someting(content)
728x90
반응형