Suchen Sie CSV -Dateien nach Text

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import csv, os, glob
#input keywords to  search
keywords = ('113006249')
 
path = r'F:\Attachments\*.csv'
 
for Tname in glob.glob(path):
     
    #read csv, and split on "," the line
    csv_file = csv.reader(open(Tname, "r", encoding='utf-8'), delimiter=",")
 
    #loop through the csv list
    for row in csv_file:
        with open(r'F:\Attachments\Results\results.txt', 'w') as f:
            if keywords == row[0]:
            # print(row)  If i just print the results out to the console, i get what i need
            # print (os.path.basename(Tname))  If i just print the results out to the console, i get what i need
 
 
                f.write(' '.join(row))  but when i try to write the results to a file, i dont get anything
                #f.write(os.path.basename(Tname))  this is also something i need in the file so we know what attachment the number was found in
Courageous Camel