Python Forum

Full Version: Find (each) element from a list in a file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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?
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.
OK. got it!
Thank you!