Python:如果条件为true,则跳过For循环中的迭代

Python:如果条件为true,则跳过For循环中的迭代,python,excel,for-loop,if-statement,continue,Python,Excel,For Loop,If Statement,Continue,我已经编写了一个Python脚本,它从Excel工作表中读取值并遍历行 但是,如果满足某个条件,我希望程序跳过一行 我有一个xml文件,它的值决定了运行类型。在python代码中,我编写了一个If/Else块来将值转换为数字(见下文) 接下来,我有一个for循环,它遍历行(参见下面的代码) 问题:我的预期是,如果一行中出现以下情况之一,程序将跳过一行 测试运行类型值为“3”,健全性检查值为False 测试运行类型值为“2”,冒烟检查值为False 测试运行类型值为“1”,回归检查值为False

我已经编写了一个Python脚本,它从Excel工作表中读取值并遍历行

但是,如果满足某个条件,我希望程序跳过一行

我有一个xml文件,它的值决定了运行类型。在python代码中,我编写了一个If/Else块来将值转换为数字(见下文)

接下来,我有一个for循环,它遍历行(参见下面的代码)

问题:我的预期是,如果一行中出现以下情况之一,程序将跳过一行

  • 测试运行类型值为“3”,健全性检查值为False
  • 测试运行类型值为“2”,冒烟检查值为False
  • 测试运行类型值为“1”,回归检查值为False
但是,程序不会跳过任何行

我拍摄了Excel表格的屏幕截图

根据工作表(见附图),当测试运行类型值为“3”但不是“3”时,程序应跳过第一行。程序迭代所有行(即使test\u run\u type\u值为1、2或3)

提前谢谢

这将
test\u run\u type\u值设置为字符串
'1'

if test_run_type_value == 1 …
这将
测试运行类型值
整数
1
进行比较

所以你基本上是在比较字符串和整数,它们永远不相等:

>>> '1' == 1
False
因此,决定是使用字符串还是整数。例如,如果分配
1
,它应该可以正常工作:

test_run_type_value = 1 # no quotes => int!
顺便说一句,您不需要这样做:

else:
    pass
只需不包含else,如果条件不正确,则不会执行任何操作:

if test_run_type_value == 3 and sanity_check == "False":
    continue
if test_run_type_value == 2 and smoke_check == "False":
    continue
if test_run_type_value == 1 and regression_check == "False":
    continue

else:pass
完全没有意义,您应该将其忽略。
test\u run\u type\u value='3'
test\u run\u type\u value==3
test_run_type_value = 1 # no quotes => int!
else:
    pass
if test_run_type_value == 3 and sanity_check == "False":
    continue
if test_run_type_value == 2 and smoke_check == "False":
    continue
if test_run_type_value == 1 and regression_check == "False":
    continue