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
Python

Avatar of undefined
Last Comment
mish33

8/22/2022 - Mon
SOLUTION
w00te

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
mish33

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck