0
我试图搜索目录中任何.csv文件中的第一列是否具有以下值:TPW或KPM1或KPM2Python:在第一列搜索目录中的.csv文件的第一列
如果是的话我想把这个文件名写入文件“Outfile_Files.txt”。
我仍然无法正确搜索;请赐教。
import os
import string
outfile = open("Outfile_Files.txt","w")
for filename in os.listdir("."):
if filename.endswith('.csv'):
with open(filename, 'r') as f:
for line in f:
words = line.split(",")
if words[0] in "TPW" or "KPM1" or "KPM2":
print words[0]
outfile.write(filename+ '\n')
break;
outfile.close()