Link to home
Start Free TrialLog in
Avatar of Suhas .
Suhas .Flag for United States of America

asked on

compare two text files

Hi Experts,
I am new to Python. The query is to Compare the 4th filed of two text files if the difference is greater than or less than 15%, then we need to print the filenames.

The two text files are attached and the code i tried is also attached.
arr1 = []
arr2 = []


for line1 in open("testReport_flame3_0202.txt"):
    linesa= line1.strip().split(",")
    arr1.append(linesa[4])
for line2 in open("testReport_flame3_0209.txt"):
    linesb= line2.strip().split(",")
    #print linesb[4]
    arr2.append(linesb[4])

lenth = len(open("testReport_flame3_0202.txt").readlines())

for i in range(1,lenth):
   if((((arr1[i] - arr2[i])/arr1[i])*100) > 15):   # failing at this step
       print i

# after this i am not getting how to fetch the respective filename

Open in new window

testReport-flame3-0202.txt
testReport-flame3-0209.txt
SOLUTION
Avatar of w00te
w00te
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial