如果在以下代码中满足条件,我如何从csv文件中打印行?
import csv
with open('eggs.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',' )
for row in spamreader:
s = (', '.join(row))
if any("Open Positions, " in s):
# gives TypeError: 'bool' object is not iterable !!!
print(s)
在没有if any("....
语句的情况下,代码打印得非常好。
答案 0 :(得分:0)
知道了!代码是:
import csv
key = ['Open Positions', 'Status']
with open('eggs.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',' )
for row in reader:
# print(row) # Check to see content of csv in list
s=row[0:2] # number of columns against key
if s == key:
print(row)