If you have to get the variety of strains in a file, or the road rely complete from a file, utilizing Python, then you should utilize one of many following choices:
Choice 1 – Utilizing open()
and sum()
with open('listing/file.txt') as myfile:
total_lines = sum(1 for line in myfile)
print(total_lines)
Choice 2 – Utilizing mmap
import mmap
with open('listing/file.txt', "r+") as myfile:
mm = mmap.mmap(myfile.fileno(), 0)
total_lines = 0
whereas mm.readline():
total_lines += 1
print(total_lines)
Choice 3 – Utilizing file.learn()
strains = 0
dimension = 1024 * 1024
with open(r'listing/file.txt', "r+") as myfile:
read_file = myfile.learn
buffer = read_file(dimension)
whereas buffer:
strains += buffer.rely('n')
buffer = read_file(dimension)
if (strains != 0):
strains += 1
print(strains)