I am trying to open a file, and count the number of lines there are in the file.
The code I am using for this is:
def line_Count(x):
with open(x,'r') as iFile: # Open passed in file
lines = iFile.readlines() # Read each line in the file
line_Count = len(lines) # Count the number of lines
return line_Count # Return the line count
This works fine for small amounts of data (10k lines in 0.073 seconds).
However, for large files (1m lines), it is taking more than 15 minutes to complete.
Is there a faster way of completing the task?
The previous example is from more than 5 years ago, and some of the solutions have been deprecated since.