Skip to content

Commit

Permalink
Merge branch '3.x.x' of github.com:c0fec0de/anytree
Browse files Browse the repository at this point in the history
  • Loading branch information
c0fec0de committed Oct 11, 2023
2 parents f6cca37 + 40e6da4 commit 0d701da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
11 changes: 10 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Subtree rendering:
Node('/Mary/Udo/Marc')
└── Node('/Mary/Udo/Marc/Lian')

Cut:
Cut/Delete:

>>> dan.parent = None
>>> print(RenderTree(dan))
Expand All @@ -181,6 +181,15 @@ Node('/Dan')
├── Node('/Dan/Jan')
└── Node('/Dan/Joe')

>>> print(RenderTree(mary))
Node('/Mary')
├── Node('/Mary/Urs')
├── Node('/Mary/Chris')
├── Node('/Mary/Marta')
└── Node('/Mary/Udo')
└── Node('/Mary/Udo/Marc')
└── Node('/Mary/Udo/Marc/Lian')

**Extending any python class to become a tree node**

The enitre tree magic is encapsulated by :any:`NodeMixin`,
Expand Down
22 changes: 16 additions & 6 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,36 @@ Every node has a :any:`children` attribute with a tuple of all children:
>>> lian.children
()

**Single Node Attach**
**Add: Single Node Attach**

Just set the parent attribute and the node becomes a child node:

>>> marc.parent = udo
>>> print(RenderTree(udo))
Node('/Udo')
└── Node('/Udo/Marc')
└── Node('/Udo/Marc/Lian')

**Single Node Detach**
**Delete: Single Node Detach**

To make a node to a root node, just set this attribute to `None`.
A node becomes a root node, if you set the parent attribute to `None`:

>>> marc.is_root
>>> lian.is_root
False
>>> marc.parent = None
>>> marc.is_root
>>> lian.parent = None
>>> lian.is_root
True

The node is deleted from the tree:

>>> print(RenderTree(udo))
Node('/Udo')
└── Node('/Udo/Marc')

**Modify Multiple Child Nodes**

Assume the following tree:

>>> n = Node("n")
>>> a = Node("a", parent=n)
>>> b = Node("b", parent=n)
Expand Down

0 comments on commit 0d701da

Please sign in to comment.