I am using read_dot from pydot (v. 1.4.2-2) and networkx (v. 2.8.8-1ubuntu1), in Python3 (v. 3.12.3).
Sometimes read_dot add an extra vertex with label “n”. I noticed that this has some relation with the presence of a “;” at the end of the last line. For instance, consider the simple code below, in a file named t.
import sys
import networkx as nx
g = nx.Graph(nx.nx_pydot.read_dot(sys.stdin))
print(g,file=sys.stderr)
nx.nx_pydot.write_dot(g,sys.stdout)`
Also, consider an input file, name test1.dot.
graph {
1 -- 2;
}
The output of the command
`$ t < test1.dot
gives the output below.
Graph named 'G' with 3 nodes and 1 edges
strict graph "G" {
"n";
1;
2;
1 -- 2;
}
Note that there is an extra vertex.
If we remove the “;” from the input file, the output is correct.
Graph named 'G' with 2 nodes and 1 edges
strict graph "G" {
1;
2;
1 -- 2;
}
Have someone noticed that error before? Is that a real bug or I am using it in the wrong way?
André Guedes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.