python简单读取大文件的方法

yipeiwu_com6年前Python基础

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

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

with open(...) as f:
 for line in f:
  <do something with line>

例如:

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相关内容感兴趣的读者可查看本站专题:《Python文件与目录操作技巧汇总》、《Python图片操作技巧总结》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python数据结构与算法教程

希望本文所述对大家Python程序设计有所帮助。

相关文章

Python实现求一个集合所有子集的示例

方法一:回归实现 def PowerSetsRecursive(items): """Use recursive call to return all subsets of it...

Python中的列表知识点汇总

Python list 在介绍 Python tuple 时,我使用了类比的方法,将其比做一个袋子,您可以在袋子中存放不同的东西。Python list 与此非常类似,因此,它的功能与袋...

Python urlopen()函数 示例分享

好了,废话少说,我们先看看几个示例吧 一、打开一个网页获取所有的内容 复制代码 代码如下:from urllib import urlopendoc = urlopen("http://...

Python 条件判断的缩写方法

return (1==1) ? "is easy" : "my god" //C...

Python 判断 有向图 是否有环的实例讲解

实例如下: import numpy from numpy import * def dfs( v ): vis[v] = -1 flag = 0 for i in range...