I am trying to print related graph components. But his print is an object generator.
This is my graph.py
import networkx as nx
import matplotlib.pyplot as plt
import csv
import sys
def buildG(G, file_, delimiter_):
reader = csv.reader(open(file_), delimiter=delimiter_)
for line in reader:
if float(line[2]) != 0.0:
G.add_edge(int(line[0]),int(line[1]),weight=float(line[2]))
def main():
graph_fn="tempset3.txt";
G = nx.Graph()
buildG(G, graph_fn, ',')
print G.nodes()
print G.number_of_nodes()
n = G.number_of_nodes()
print ("no of nodes: ", n)
comps=nx.connected_components(G)
print comps
main()
This is my tempset3.txt
0,1,9
1,3,5
1,4,17824
2,5,1199
2,6,729
5,7,619
5,8,241
5,10,227
7,8,4
When I run it, it gives:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 10]
10
('no of nodes: ', 10)
<generator object connected_components at 0x360f140>
How to print connected components ???
The output should be: [[0, 1, 3, 4], [2, 5, 6, 7, 8, 10]]