我有一个很长的程序与代码块的这部分故障列表索引必须是整数,而不是名单 - 在python
print GInfo[i].DualVariables, "\n", GInfo[i].Components
for i in GInfo[i].Components:
print i, tuple(i)
if (tuple(i) not in GInfo[i].DualVariables):
------ Do Something ---------
这里ginfo显示是一个类的对象GraphInfo
使用快译通class GraphInfo:
def __init__(self):
self.G = nx.Graph()
self.Components = []
self.ActiveStatus = {}
self.ContainsCommon = {}
self.p = {}
self.Edges = []
self.DualVariables = {}
self.Bound = {}
正如人们可以看到DualVariables是一个字典,Components是一个列表。对于该代码的样品实例的输出如下所示:
{(0,): 0.0, (1,): 31.5, (2,): 31.5, (8,): 31.5, (3,): 31.5, (4,): 31.5, (5,): 31.5,(6,): 31.5, (7,): 31.5}
[[8, 7], [0], [1], [2], [3], [4], [5], [6]]
[8, 7] (8, 7)
接着误差
TypeError: list indices must be integers, not list
在其中如果条件是存在的线。
任何有关这个问题的帮助表示赞赏。
这样做。谢谢 – user62089 2013-02-15 21:04:39
@pondy太棒了!那么请允许我问你答案是否正确? :) – piokuc 2013-02-15 21:07:18