python - Int Object Is Not Iterable -
i have come across problem don't know how resolve involving dijkstra's algorithm - here code:
infinity = 1000000 invalid_node = -1 #startnode = 0 class node: distfromsource = infinity previous = invalid_node visited = false def populatenodetable(): nodetable = [] f = open("twodarray.txt", "r") line in f.readlines(): #get number of nodes file nodetable.append(line.split(',')) # create matrix of weights numnodes = len(nodetable) # count nodes print numnodes #for nodes in text file, set visited false, distfromsource infinity & predecessor none **for in numnodes: nodetable.append(node(i))** #nodetable.append(node()) nodetable[startnode].distfromsource = 0 print nodetable if __name__ == "__main__": populatearray() populatenodetable()
when run code following error:
traceback (most recent call last): file "2darray.py", line 63, in <module> populatenodetable() file "2darray.py", line 18, in populatenodetable in numnodes: typeerror: 'int' object not iterable
i not sure how rectify error (the section between asterix) - trying read text file series of integers separated commas, , count number of nodes within text file each node assigned values in node class
try this:
for in nodetable:
why trying iterate on numnodes
? defined 1 line above length of table.
but appending same table in loop doesn't make sense. , not work code reads file. node class isn't usable @ ...
Comments
Post a Comment