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

Python simply reads large files

高洛峰
Release: 2017-03-01 13:29:03
Original
1247 people have browsed it

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>
Copy after login

For example:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template