Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all edges on a given node #260

Open
leek2 opened this issue Mar 17, 2021 · 4 comments
Open

Get all edges on a given node #260

leek2 opened this issue Mar 17, 2021 · 4 comments

Comments

@leek2
Copy link

leek2 commented Mar 17, 2021

I'm trying to walk a dot graph I read in, and I can't find any way to ask for a list of all edges (or all in edges, or out edges) on a given node. If I know there is an edge from A->B, I can: graph.get_edge("A", "B"). But there doesn't seem to be anyway to ask for "All out edges on A." I tried a variety of things like this, but just got an empty list: graph.get_edge("A")

Right now I've just made my own data structures to work around this, but it seems like an odd oversight to me. Maybe I'm missing something?

@felix-hilden
Copy link

I'm not sure about the official approach of Pydot to this, but these sorts of things were my reason to using NetworkX, which seems to be highly compatible with Pydot. So in essence: analysis with NetworkX, dotfile and Graphviz operations with Pydot. In my humble opinion it's fine for Pydot to remain "just" an interface to Graphviz.

@sahansk2
Copy link

sahansk2 commented Apr 22, 2021

In the Python interpreter, running help() on a Dot object shows that there is indeed a function to get all edges: get_edges(). Might this be what you want, @leek2 ?

Using the official documentation as an example:

import pydot

dot_string = """graph my_graph {
    bgcolor="yellow";
    a [label="Foo"];
    b [shape=circle];
    a -- b -- c [color=blue];
}"""

graphs = pydot.graph_from_dot_data(dot_string)
graph = graphs[0]
print(graph.get_edges()) # prints list of Edge objects

@leek2
Copy link
Author

leek2 commented Apr 22, 2021

sahansk2, thank you for the suggestion, but no. That gets all edges on the graph. I want to be able to ask for just the edges on a given node. Of course I can extract that from all the edges, but it would be nice if pydot had a more straight-forward way to do it.

@sahansk2
Copy link

Oh, sorry for misreading your question. Then, I haven't seen anything in pydot to directly support this functionality, which is a real shame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants