문제

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.

도움이 되었습니까?

해결책

Within

class Node:

implement

    def __repr__(self):
        return "Node(id={0.id})".format(self)

This tells python how to represent your class.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top