Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

load a graph from a dot file

Sage allows me to get the representation of a Graph, G, in the dot language by using the method

G.graphviz_string()

I can even have this string written directly to a file by using:

G.graphviz_to_file_named('my_graph_file.dot')

Is there a way of reloading G from such a file? I tried doing

G = Graph('my_graph_file.dot')

G = Graph(open('my_graph_file.dot'))

G = Graph(open('my_graph_file.dot').read())

Where the contents of 'my_graph_file.dot' are:

graph MyGraph{

foo -- {bar}

bar -- {foo; bas}

bas -- {bar}

}

But none of these worked.

load a graph from a dot file

Sage allows me to get the representation of a Graph, G, in the dot language by using the method

G.graphviz_string()

I can even have this string written directly to a file by using:

G.graphviz_to_file_named('my_graph_file.dot')

Is there a way of reloading G from such a file? I tried doing

G = Graph('my_graph_file.dot')

G = Graph(open('my_graph_file.dot'))

G = Graph(open('my_graph_file.dot').read())

Where the contents of 'my_graph_file.dot' are:

graph MyGraph{

foo -- {bar}

bar -- {foo; bas}

bas -- {bar}

}

But none of these worked.