Python Forum
Still do not get how Python iterates over a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Still do not get how Python iterates over a file
#4
Here you go.
I'm using a file and a list.
File:
ZPM911
ZPM1912
ZPM1919
ZPM4555
ZPM4556
ZPM4557
Snippet:
ff=open("c:/02/TTST.txt",'r')
list_1=ff.readlines()
 
list_2 = ['ZPM911,UP,DOWN','ZPM1912,UP,UP','ZPM1919,DOWN,DOWN']
 
for el in list_1 :
    el=el.strip()
     
    for ehl in list_2 :   
        ehl=ehl.strip()
        sp0,*stuff = ehl.split(",")       
        if  el == sp0 :
            print(f" Matched ++++++ {el}")        
        else :
            print(f" Not Matched -- {el}")
ff.close()  
Reply


Messages In This Thread
RE: Still do not get how Python iterates over a file - by tester_V - Aug-21-2021, 06:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Do not get how Python iterates over a file tester_V 12 1,894 Jan-29-2023, 01:49 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020