HomeSoftware EngineeringHow one can Get the Variety of Strains in a File in...

How one can Get the Variety of Strains in a File in Python

If it’s essential get the variety of traces in a file, or the road depend complete from a file, utilizing Python, then you should use one of many following choices:

Possibility 1 – Utilizing open() and sum()

with open('listing/file.txt') as myfile:
    total_lines = sum(1 for line in myfile)


Possibility 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


Possibility 3 – Utilizing file.learn()

traces = 0
measurement = 1024 * 1024

with open(r'listing/file.txt', "r+") as myfile:
    read_file = myfile.learn

    buffer = read_file(measurement)
    whereas buffer:
        traces += buffer.depend('n')
        buffer = read_file(measurement)

if (traces != 0):
    traces += 1


Most Popular

Recent Comments