Mar-29-2021, 04:17 AM
Greetings!
For some reason, I do not get the iterations in Python.
Especially with "Else".
here is a problem, I have two files, File-1 and File-2. I must use File-1 lines to find lines in File-2.
I have no problem finding lines but I cannot print Lines that do not match (from File-2)
File-1 lines:
03/28/2021,P,6,LINE2
03/28/2021,P,9,LINE4
File-2 lines:
03/28/2021,P,16,LINE1
03/28/2021,P,6,LINE2
03/28/2021,P,9,LINE3
03/28/2021,P,9,LINE4
03/28/2021,P,8,LINE5
03/28/2021,S,95,LINE6
03/28/2021,S,1,LINE7
03/28/2021,P,46,LINE8
I need to print out only lines that do not match:
03/28/2021,P,16,LINE1
03/28/2021,P,9,LINE3
03/28/2021,P,8,LINE5
03/28/2021,S,95,LINE6
03/28/2021,S,1,LINE7
03/28/2021,P,46,LINE8
But the code I wrote prints this:
ELSE -->> 03/28/2021,P,16,LINE1
ELSE -->> 03/28/2021,P,9,LINE3
ELSE -->> 03/28/2021,P,9,LINE4
ELSE -->> 03/28/2021,P,8,LINE5
ELSE -->> 03/28/2021,S,95,LINE6
ELSE -->> 03/28/2021,S,1,LINE7
ELSE -->> 03/28/2021,P,46,LINE8
ELSE -->> 03/28/2021,P,16,LINE1
ELSE -->> 03/28/2021,P,6,LINE2
ELSE -->> 03/28/2021,P,9,LINE3
ELSE -->> 03/28/2021,P,8,LINE5
ELSE -->> 03/28/2021,S,95,LINE6
ELSE -->> 03/28/2021,S,1,LINE7
ELSE -->> 03/28/2021,P,46,LINE8
I have to split lines in File-1 and File-2, some additional processing required in the lines.
Here is the code:
I tried to move "else" all over the place and used "break" but still cannot make a clean print of only the 'Not Matched' lines.
Thank you.
For some reason, I do not get the iterations in Python.
Especially with "Else".
here is a problem, I have two files, File-1 and File-2. I must use File-1 lines to find lines in File-2.
I have no problem finding lines but I cannot print Lines that do not match (from File-2)
File-1 lines:
03/28/2021,P,6,LINE2
03/28/2021,P,9,LINE4
File-2 lines:
03/28/2021,P,16,LINE1
03/28/2021,P,6,LINE2
03/28/2021,P,9,LINE3
03/28/2021,P,9,LINE4
03/28/2021,P,8,LINE5
03/28/2021,S,95,LINE6
03/28/2021,S,1,LINE7
03/28/2021,P,46,LINE8
I need to print out only lines that do not match:
03/28/2021,P,16,LINE1
03/28/2021,P,9,LINE3
03/28/2021,P,8,LINE5
03/28/2021,S,95,LINE6
03/28/2021,S,1,LINE7
03/28/2021,P,46,LINE8
But the code I wrote prints this:
ELSE -->> 03/28/2021,P,16,LINE1
ELSE -->> 03/28/2021,P,9,LINE3
ELSE -->> 03/28/2021,P,9,LINE4
ELSE -->> 03/28/2021,P,8,LINE5
ELSE -->> 03/28/2021,S,95,LINE6
ELSE -->> 03/28/2021,S,1,LINE7
ELSE -->> 03/28/2021,P,46,LINE8
ELSE -->> 03/28/2021,P,16,LINE1
ELSE -->> 03/28/2021,P,6,LINE2
ELSE -->> 03/28/2021,P,9,LINE3
ELSE -->> 03/28/2021,P,8,LINE5
ELSE -->> 03/28/2021,S,95,LINE6
ELSE -->> 03/28/2021,S,1,LINE7
ELSE -->> 03/28/2021,P,46,LINE8
I have to split lines in File-1 and File-2, some additional processing required in the lines.
Here is the code:
with open (file_2,'r') as l_few : f2=l_few.readlines() with open (file_1,'r') as f1: for lf1 in f1: lf1=lf1.strip() sp1 = lf1.split(",") for lf2 in f2 : lf2=lf2.strip() if lf2 : if sp1[3] in lf2 : spL2=lf2.split(",") #print (" File 2 Line matched --> "+lf2) #break else : print (" ELSE -->> "+lf2) #breakAny help appreciated, I exhausted my resources, trying to solve it for the last 3 days.
I tried to move "else" all over the place and used "break" but still cannot make a clean print of only the 'Not Matched' lines.
Thank you.