首页 > 解决方案 > 调试时如何查看for循环中每个迭代/步骤的输出

问题描述

我有一个嵌套的 for 循环,我需要在每次迭代中查看输出以进行调试。我怎样才能做到这一点?

这是我需要查看输出的示例代码。

for sheet_name, df in Input_Data.items():
    for line in df:
        if line.startswith('Linear'):
            index = line.index('Linear')
            break

标签: pythonpandas

解决方案


尝试这个:

for sheet_name, df in Input_Data.items():
    for line in df:

        print(line) # just print the line

        if line.startswith('Linear'):
            index = line.index('Linear')      

            break

推荐阅读