首页 > 代码库 > python 读取大文件
python 读取大文件
要读取个大文件,文件大概是3G左右,担心read会出现内存溢出的情况,网上找了个靠谱的用法:
with open(...) as f: for line in f: <do something with line>
The with
statement handles opening and closing the file, including if an exception is raised in the inner block. The for line in f
treats the file object f
as an iterable, which automatically uses buffered IO and memory management so you don‘t have to worry about large files.
There should be one -- and preferably only one -- obvious way to do it.
python 读取大文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。