Python Forum
Find (each) element from a list in a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find (each) element from a list in a file
#1
Greetings!
I want to scan a .csv file, find cells with dates, and create a list of dates.
then I'd like to check the same file and find strings that contain the dates from the list.
I'm going to process the lines later.
Here is the code that does not work Sad
with open('C:/01/Logs_Scan_removed_prt.csv','r') as ftor :
    for el in ftor :
        el.strip()
        el=el.split(",")
        tof = el[4]
        dates.append(el[4])       
    for el in ftor :
        #print(el)    
        for ed in dates :
            print(f" ++ {ed}")
            if ed in el :
                print(f" found Line -> {el}")
Thank you.
Reply
#2
The line el.strip() does nothing. You can remove it. Similarly the variable tof = el[4] is not used. You can remove that line too.

Which output are you expecting? Suppose that you already have the list of dates and you have a file with lines that contain zero or more of these dates. What should the output look like?
Reply
#3
Simply saying "it does not work" is of no use to anyone outside of your head.

What is it that you're expecting?

It would be of help to have a sample of the data: that .csv file could be most anything.

You may want to explain the meaning behind el, ftor, ed: these mean nothing. One of the many useful features of Python, is the ability to use meaningful names for variables and as such there's no need to be so cryptic.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#4
OK. got it!
Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  removing one list element without using its index paul18fr 7 1,089 Feb-22-2025, 07:59 PM
Last Post: DeaD_EyE
  question about changing the string value of a list element jacksfrustration 4 2,053 Feb-08-2025, 07:43 AM
Last Post: jacksfrustration
  extract an element of a list into a string alexs 5 3,501 Aug-30-2024, 09:24 PM
Last Post: alexs
  element in list detection problem jacksfrustration 5 1,818 Apr-11-2024, 05:44 PM
Last Post: deanhystad
  list in dicitonary element problem jacksfrustration 3 1,592 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  Program to find Mode of a list PythonBoy 6 2,444 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 3,006 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 7,021 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Cannot find py credentials file standenman 5 3,218 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 1,235 Feb-14-2023, 03:21 PM
Last Post: SouAmego22

Forum Jump:

User Panel Messages

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