循环不起作用,因为控制台不打印Hello

时间:2017-08-22 08:47:08

标签: python

maharashtra = []
maharashtradata = []
for sec in sections:
    row = 1
    for item in xmlDocTree.iter( sec ):
        if "AHMEDNAGAR" in item.text:
            maharashtra.append(row)
        row = row + 1
    col = col+1
for entry in maharashtra:
    col=0
    entrydata = {}
    for sec in sections:
        entrydata[sec] = fetched[sec][entry]
        col = col + 1
    maharashtradata.append(entrydata)

for flag in maharashtradata:
    if flag['M_Flag'] == "U":
        print "Hello"

这里maharashtradata是一个包含字典的列表。

该程序不打印Hello!

1 个答案:

答案 0 :(得分:0)

如果此程序未打印 Hello ,则表示maharashtradata列表中的字典不包含 M_Flag 键或 M_Flag值 key不等于 U

要进行调试,请尝试打印maharashtra和maharashtradata列表,并检查列表是否包含正确的数据。