У меня проблемы с питоном. Я продолжаю получать ту же ошибку:
Traceback (most recent call last):
File "F:\test4", line 21, in <module>
graph = dict([(label, node(label))] for label in node_labels)
File "F:\test4", line 21, in <genexpr>
graph = dict([(label, node(label))] for label in node_labels)
NameError: global name 'node' is not defined
# open network.txt and populate nodes and close file
network_file = open("network.txt", "r")
lines = [line.strip() for line in network_file]
network_file.close()
print (len(lines))
# edges which will be populated with information in network.txt
edges = [] # list of <label, label, distance> triples
node_labels = set() # set of node labels
graph = {} # dictionary of nodes keyed by labels
for line in lines:
strNode, strNeighbor, strMetric = line.split()[:3]
intMetric = int(strMetric)
edges.append((strNode, strNeighbor, intMetric))
node_labels.update([strNode, strNeighbor])
# create graph
graph = dict([(label, node(label))] for label in node_labels)
до этой строки, я не могу найти никаких проблем с узлом глобальной переменной, он должен работать.
Спасибо!