Aug-13-2023, 05:00 PM
So i am having to process a few different text files, for each file i process, i need too capture runtime duration, record count and timestamp
Since i'm already using the scan_files() function is it possible to incorporate the mapcount() functionality into the main function?
I mean if im already opening up the first text file, why not get the count returned while its open. so far just adding the readline logic below the strip() in the main logic isnt working..
Since i'm already using the scan_files() function is it possible to incorporate the mapcount() functionality into the main function?
I mean if im already opening up the first text file, why not get the count returned while its open. so far just adding the readline logic below the strip() in the main logic isnt working..
# ROUTINE TO OPEN THE APPROPRIATE TEXT FILES TO PROCESS THE IP LIST def scan_files(): directory = '.' for entry in os.scandir(directory): if entry.is_file() and entry.name.endswith('.txt'): if 'ip_list' in entry.name: pt = directory + '/' + entry.name with open(pt) as file: for ip in file: yield ip.strip() # ROUTINE TO GET FILE COUNT def mapcount(filename): with open(filename, "r+") as f: buf = mmap.mmap(f.fileno(), 0) lines = 0 readline = buf.readline while readline(): lines += 1 return linesI want to open the file once, get the count and move on to the rest of the script.