以下代码告诉我:local variable 'param' referenced before assignment
value_per_label = [(label, value) \
for label, value in zip(gui_names(param),values) \
for (param, values) in parameters]
我做错了什么?
参数如下所示:
parameters = [("A", (1,3,5)), ("B", (2,3,4))]
我希望将其转换为:
value_per_label = [("A_min", 1), ("A_current", 3), ("A_max", 5), ("B_min", 2), ("B_current", 3), ("BA_max", 4)]
答案 0 :(得分:3)
让我们将它转换为for循环(List comprehensions基本上更快,循环更可读):
value_per_label = []
for label, value in zip(gui_names(param), values):
for (param, values) in parameters:
value_per_label.append((label, value))
现在错误非常明显
编辑:要解决此问题,请将for循环更改为:
value_per_label = [(value, label)
for (param, values) in parameters \
for (label, value) in zip(gui_names(param), values)]
我认为这给出了相同的结果,但我没有测试它。