Skip to content

Instantly share code, notes, and snippets.

@arc279
Last active February 24, 2021 09:57
Show Gist options
  • Save arc279/47c61a20bde0157073d4b0e06530b2ec to your computer and use it in GitHub Desktop.
Save arc279/47c61a20bde0157073d4b0e06530b2ec to your computer and use it in GitHub Desktop.
import anytree
from anytree.dotexport import RenderTreeGraph
class Foo(anytree.Node):
def __init__(self, name):
super().__init__(name)
def __gt__(self, other):
other.parent = self
return other
a = Foo("A")
b = Foo("B")
c = Foo("C")
d = Foo("D")
e = Foo("E")
f = Foo("F")
a > b > c
a > d > e
b > f
print(anytree.RenderTree(a, style=anytree.AsciiStyle()))
from anytree.dotexport import RenderTreeGraph
RenderTreeGraph(a).to_dotfile("tree.dot")
"""
$ python tree.py
Foo('/A')
|-- Foo('/A/B')
| |-- Foo('/A/B/C')
| +-- Foo('/A/B/F')
+-- Foo('/A/D')
+-- Foo('/A/D/E')
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment