我要发疯了,为什么我所有的if语句都在打印。我在if语句中声明,如果子字符串“FPL”、“FCG”、“GP”不在索引5中,则不要打印if语句中的内容。不知道还能做什么。我尝试过用rps_表删除rps_表[5],但没有成功。我也尝试过使用any(“GP”)、any(“FCG”)函数。我正在尝试检查“FPL”、“FCG”或“GP”是否不在我的rps_表中
rps_表:
5412, "Test", "Test2", "test3", "test4","FPLec_4047"
5412, "Test", "Test2", "test3", "test4","FCGec_4047"
5412, "Test", "Test2", "test3", "test4","GPec_4047"
打印rps_表[5]输出:
GPec_SAP_235
FCGec_125
FPLec_4047
代码:
cd = datetime.now() - timedelta(days=1)
cd = cd.strftime('%Y/%m/%d')
rps_table_q_2 = f"""select * from test where processingdate = '{cd}' and datasetname like '%ICL%' """
rps_table_results = sql_server_cursor.execute(rps_table_q_2).fetchall()
for rps_table in rps_table_results:
print(rps_table[5])
if 'GP' not in rps_table[5]:
html_body ="File 1 Missing"
print(html_body)
html_body_l.append(html_body)
if 'FCG' not in rps_table[5]:
html_body = "File 2 Missing"
print(html_body)
html_body_l.append(html_body)
if 'FPL' not in rps_table[5]:
html_body ="File 3 Missing"
print(html_body)
html_body_l.append(html_body)
结果:
File 1 Missing
File 2 Missing
File 3 Missing
当您处理每一行结果时,您正在检查它的所有3种类型的数据。但它将只匹配其中一个,您将为其他两个打印“缺失”消息
相反,循环使用不同的前缀并检查所有行中的前缀
我还将
in
更改为.startswith()
,因为您搜索的字符串似乎总是在列的开头相关问题 更多 >
编程相关推荐