Receiving : “UnboundLocalError: local variable referenced before assignment”
我看到过很多人都有同样的问题,但由于问题的独特性,似乎已经根据具体情况提供了解决方案。
以下是我的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | loga = [(912,"Message A1") , (1000,"Message A2") , (988,"Message A3") , (1012,"Message A4") , (1002,"Message A5")] logb = [(926,"Message B1") , (1008,"Message B2") , (996,"Message B3") , (1019,"Message B4") , (1100,"Message B5")] logc = [(1056,"Message C1") , (1033,"Message C2") , (999,"Message C3") , (1054,"Message C4") , (1086,"Message C5")] logs = [loga, logb, logc] out = [] def find_lowest_i(lst): for i in range(len(lst)): log = lst[i] if log: t = log[0][0] if i==0 or t < lowest_t: lowest_i = i lowest_t = t return lowest_i while True: i = find_lowest_i(logs) print"i=", i tpl = logs[i].pop(0) print tpl out.append(tpl) print out |
我的确切错误是:
"消息文件名行位置回溯19查找最低点13UnboundLocalError:分配前引用的本地变量'lowest_t'
由于连续的
1 2 3 4 | logs = [[], [(1019, 'Message B4'), (1100, 'Message B5')], [(1056, 'Message C1'), (1033, 'Message C2'), (999, 'Message C3'), (1054, 'Message C4'), (1086, 'Message C5')]] |
在这种情况下,i=0时