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
  element in list detection problem jacksfrustration 5 367 Apr-11-2024, 05:44 PM
Last Post: deanhystad
  list in dicitonary element problem jacksfrustration 3 707 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  Program to find Mode of a list PythonBoy 6 1,101 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,587 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,222 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Cannot find py credentials file standenman 5 1,652 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 747 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  compare and find the nearest element ? mr_gentle_sausage 4 1,050 Jan-15-2023, 07:11 AM
Last Post: DPaul
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,840 Oct-26-2022, 04:03 PM
Last Post: deanhystad
  [SOLVED] [Beautifulsoup] Find if element exists, and edit/append? Winfried 2 4,307 Sep-03-2022, 10:14 PM
Last Post: Winfried

Forum Jump:

User Panel Messages

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