Is there a really efficient (FAST) way to read large text files in python?
<p>I am looking to open and fetch data from a large text file in python as fast as possible (<strong>It almost has 62603143 lines - size 550MB</strong>). As I don't want to stress my computer, I am doing it by following way ,</p>

<pre><code>import time
start = time.time()
for line in open(filePath):
    #considering data as last element in file
    if data in line:
        do_something(data)
end = time.time()
print "processing time = %s" % (count, end-start)
</code></pre>

<p>But as I am doing by above method its taking almost <strong>18 seconds</strong> to read full file ( My computer has <em>Intel i3 processor and 4 GB RAM</em> ). Likewise if file size is more it is taking more time and considering user point of view its very large. I read lot of opinions on forums, referred multiple <em>Stack Overflow</em> questions but didn't get the fast and efficient way to read and fetch the data from large files. Is there really any way in Python to read large text files in few seconds?</p>

<p>No, there is no faster way of processing a file line by line, not from Python.</p>

<p>Your bottleneck is <em>your hardware</em>, not how you read the file. Python is already doing everything it can (using a buffer to read the file in larger chunks before splitting into newlines).</p>

<p>I suggest upgrading your disk to an SSD.</p>

python python-2.7 text-files