Home  >  Article  >  Backend Development  >  Python simply reads large files

Python simply reads large files

高洛峰
高洛峰Original
2017-03-01 13:29:031171browse

The example in this article describes how to simply read large files in Python. Share it with everyone for your reference, the details are as follows:

The method used by Python to read large files (GB level) is very simple:

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

For example:

with open(filepath,&#39;r&#39;) as infile:
 for line in infile:
  print line

Everything is handled by the python interpreter, the reading efficiency is very high, and it takes up less resources.

stackoverflow reference link: How to read large file, line by line in python - Stack Overflow

For more articles related to python's simple reading of large files, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn