【发布时间】:2022-06-18 00:32:48
【问题描述】:
我有一个外部 for 循环,它遍历 excel 文件的行。 if 语句然后检查是否满足条件。如果满足条件,我想在另一个文件的行上运行另一个 for 循环,该文件将包含一个我可以与原始文件交叉引用的列。问题是每次 if 语句的计算结果为 true 时,它都应该运行嵌套循环,但由于某种原因,它只在第一次计算结果为 true 时才运行嵌套循环。
for x,y,z in rows:
#this statement evaluates to true 100 times
if (x.value == current_date):
#this inner loop should run 100 times, not once
for a,b,c in cross_referece_rows:
print(c)
【问题讨论】:
-
cross_referece_rows中的每一项都会打印一次
-
什么是
cross_referece_rows?听起来像是你用尽了一些迭代器。
标签: python datetime openpyxl nested-loops