Dec-10-2020, 04:25 AM
Greetings!
I have a list of error codes and I'm trying to find/count each error in each file and print them like this
"error - 1002x01 - 11"
"error - 1001x01 - 8"
and so on.
I wrote a code to do this but having a problem printing "error code - number of errors"
I have a list of error codes and I'm trying to find/count each error in each file and print them like this
"error - 1002x01 - 11"
"error - 1001x01 - 8"
and so on.
I wrote a code to do this but having a problem printing "error code - number of errors"
import os
list = ['100x02','1001x03'] # list of errors#
path = 'C:\\02'
for root,dirs, files in os.walk(path):
for ef in files :
cur_ef = os.path.join(path,ef)
if os.path.isfile(cur_ef):
with open (cur_ef,'r') as fto_read :
count = 0
for e_ln in fto_read : # reading each line from a file #
e_ln=e_ln.rstrip()
#print (e_ln)
for e_el in list : # reading an element from the list #
if e_el in e_ln :
e_el=e_el.rstrip()
#print ("FOUND LINE --->> ",e_ln)
count+=1
print ("Error Name ",e_el)
print ("Number of Errors ---- >> ",count)
