试图筛选出字符串中没有“PC”的数据,但它似乎没有捕获任何内容,只是转到了“else”。不确定csvRow是否是一个字符串,也许这就是它不起作用的原因,但我刚刚开始使用Python,不知道如何解释它
csvRow返回的示例数据:
['0', '0', '30', 'Testing Unit', 'True', 'COMP_PC', 'COMP_PC']
['0', '0', '30', 'Prod Unit', 'True', 'ASSM_UL', 'ASSM_UL']
代码:
for csvRow in reader(csvRows[2:]):
if "PC" in csvRow:
for csvValue in csvRow:
values += csvValue + "\t"
values = values[:-1] + "\r\n"
else:
continue
编辑:
为此拼凑了一个解决方案,尽管我不确定它是否有效。 有什么建议吗
for csvRow in reader(csvRows[2:]):
for csvValue in csvRow:
if "PC" in csvValue:
for csvValue2 in csvRow:
values += csvValue2 + "\t"
values = values[:-1] + "\r\n"
break
else:
continue
正如furas所说的那样,我明白了:
只需反复浏览列表并在那里进行检查
即使您想使用另一个分隔符(即} module 仍然是一个好主意。它将更好地生成格式良好的输出
\t
而不是,
),使用the ^{下面是一个例子:
输出:
相关问题 更多 >
编程相关推荐