Last active
February 24, 2021 09:57
-
-
Save arc279/47c61a20bde0157073d4b0e06530b2ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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