Nov-01-2020, 04:13 AM
Happy Hollowing! If there is such a thing...
I'm scanning files for specific lines, If lines found I append them to lists and count matched lines.
I need to print only the last line from each list and the count number (of matched lines).
I'm using Try/Except to handle empty lists and having a problem with "print". The script I wrote prints only one Print statement,
I need to print a lot more than one.
I'm scanning files for specific lines, If lines found I append them to lists and count matched lines.
I need to print only the last line from each list and the count number (of matched lines).
I'm using Try/Except to handle empty lists and having a problem with "print". The script I wrote prints only one Print statement,
I need to print a lot more than one.import os
import os.path
import re
from itertools import islice
import io
t0 ='Error 0'
t1 ='Error 1'
logDir = 'C:/Log_Dir/'
with open('C:/somedir/Errors_detailes.txt','w') as fout_w : ## Append Mode ##
fout_w.write("line1"+'\n')
for fn in os.listdir(logDir):
if os.path.isfile(os.path.join(logDir, fn)):
dir_f = logDir+fn
mylst1 = []
with io. open(dir_f, encoding='utf-8', errors='ignore') as f :
cnttt =0
cntt1 =0
lstt0=[]
lstt1=[]
for line in f :
if t0 in line:
cnttt+=1
lstt0.append(line)
#print (fn+"----->> "+line)
elif t1 in line:
cntt1+=1
lstt1.append(line)
# print (fn+"----->> "+line)
try :
print ("-- Count of 'Error - 0' Errors -- "+ str(cnttt)+" --->>> "+lstt0[-1]+"\n")
print ("-- Count of 'Error - 1' Errors -- "+ str(cntt1)+" --->>> "+lstt1[-1]+"\n")
except Exception as ex:
print(ex)Thank you!
