Reputation: 4795
I am using networkx
, with my own custom Node
class. When I run nx.write_dot(G, "graph.py")
, I get the node object in the output, as such:
strict graph {
graph [bb="0,0,289.87,36"];
node [label="\N"];
"<node.Node object at 0x10425f550>" [height=0.5,
pos="144.94,18",
width=4.026];
}
How can I make networkx
output the relevant attribute? My Node
class has an id
field that I want it to be labeled by.
Upvotes: 0
Views: 536
Reputation: 122059
Within
class Node:
implement
def __repr__(self):
return "Node(id={0.id})".format(self)
This tells python how to repr
esent your class.
Upvotes: 1