print graph not available

52 views
Skip to first unread message

Peng Yu

unread,
May 4, 2012, 5:01:44 PM5/4/12
to networkx-discuss
Hi,

I feel that it is inconvenient that Graph (and DiGraph) does not offer
a way to print them. I'm wondering if it is better to add a way to
print a graph.

import networkx as nx

G=nx.Graph()
G.add_node("spam")
G.add_edge(1,2)
print(G.nodes())
print(G.edges())
print(G) # This doesn't print anything.


Regards,
peng

Aric Hagberg

unread,
May 4, 2012, 6:35:38 PM5/4/12
to networkx...@googlegroups.com
When you call print(G) it tries to print the graph name. In your case
a name wasn't specified so you got an empty string.

In [1]: import networkx as nx

In [2]: G=nx.Graph(name='tom')

In [3]: print(G)
tom

In [4]: G=nx.path_graph(4)

In [5]: print(G)
path_graph(4)

Aric
Reply all
Reply to author
Forward
0 new messages