Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用“不在”时正在打印语句_Python_Sql Server - Fatal编程技术网

Python 使用“不在”时正在打印语句

Python 使用“不在”时正在打印语句,python,sql-server,Python,Sql Server,我要发疯了,为什么我所有的if语句都在打印。我在if语句中声明,如果子字符串FPL、FCG、GP不在索引5中,则不打印if语句中的内容。不知道还能做什么。我尝试过用rps_表删除rps_表[5],但没有成功。我还尝试过使用anyGP、anyFCG函数。我正在尝试检查“FPL”、“FCG”或“GP”是否不在我的rps_表中 rps_表: 5412, "Test", "Test2", "test3", "test4",&

我要发疯了,为什么我所有的if语句都在打印。我在if语句中声明,如果子字符串FPL、FCG、GP不在索引5中,则不打印if语句中的内容。不知道还能做什么。我尝试过用rps_表删除rps_表[5],但没有成功。我还尝试过使用anyGP、anyFCG函数。我正在尝试检查“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
代码:

结果:

File 1 Missing
File 2 Missing
File 3 Missing

当您处理每一行结果时,您正在检查它的所有3种类型的数据。但它将只匹配其中一个,您将为其他两个打印丢失的消息

相反,循环使用不同的前缀并检查所有行中的前缀

required_prefixes = ['GP', 'FCG', 'FPL']
for i, prefix in enumerate(required_prefixes, 1):
    if not any(row[5].startswith(prefix) for row in rps_table_results):
        html_body = f'File {i} missing'
        print(html_body)
        html_body_l.append(html_body)

我还将in改为.startswith,因为您搜索的字符串似乎总是在列的开头。

您的输出不完整,printrps_table[5]在每种情况下打印什么?@Selcuk hi,它在表块中。这是所有3行中的第5位。GPec_SAP_235、FCGec_125、FPLec_4047请编辑您的问题并逐字发布整个输出。第1行没有FCG或FPL,因此您在处理该行时会收到这些消息。@Barmarim正在检查“FPL”、“FCG”或“GP”是否不在我的rps_表中。谢谢!!!你能简单地解释一下我做错了什么吗?是因为我在搜索GP,而GP行没有被迭代吗?是的。在每一行中,检查每个前缀。但是一行只能有一个前缀。
required_prefixes = ['GP', 'FCG', 'FPL']
for i, prefix in enumerate(required_prefixes, 1):
    if not any(row[5].startswith(prefix) for row in rps_table_results):
        html_body = f'File {i} missing'
        print(html_body)
        html_body_l.append(html_body)