python简单读取大文件

本文实例讲述了python简单读取大文件的方法。分享给大家供大家参考,具体如下:

python读取大文件(gb级别)采用的办法很简单:

with open(…) as f:
for line in f:

例如:

with open(filepath,’r’) as infile:
for line in infile:
print line

一切都交给python解释器处理,读取效率很高,且占用资源少。

stackoverflow参考链接:how to read large file, line by line in python – stack overflow

更多python简单读取大文件相关文章请关注php中文网!

Posted in 未分类

发表评论