I am currently using the following python code:
file = open(filePath, "r")
lines=file.readlines()
file.close()
Say my file has several lines (10,000 or more), then my program becomes slow if I do this for several files. Is there a way to speed this up in Python? Reading various links I understand that readlines stores the lines of a file in memory, so the code slows down.
I also tried using the following code, and the time I got is 17%.
lines=[line for line in open(filePath,"r")]
Is there any other module in python2.4 (which I could skip). Thanks, Sandhya
source
share