Getting started
Usage is simple.
Construction
>>> from anytree import Node, RenderTree
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> dan = Node("Dan", parent=udo)
>>> jet = Node("Jet", parent=dan)
>>> jan = Node("Jan", parent=dan)
>>> joe = Node("Joe", parent=dan)
Node
>>> print(udo)
Node('Udo')
>>> print(joe)
Node('Udo/Dan/Joe')
Tree
>>> for pre, fill, node in RenderTree(udo):
... print("%s%s" % (pre, node.name))
Udo
├── Marc
│ └── Lian
└── Dan
├── Jet
├── Jan
└── Joe
Manipulation
A second tree:
>>> mary = Node("Mary")
>>> urs = Node("Urs", parent=mary)
>>> chris = Node("Chris", parent=mary)
>>> marta = Node("Marta", parent=mary)
>>> print(RenderTree(mary))
Node('Mary')
├── Node('Mary/Urs')
├── Node('Mary/Chris')
└── Node('Mary/Marta')
Append:
>>> udo.parent = mary
>>> 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')
└── Node('Mary/Udo/Dan')
├── Node('Mary/Udo/Dan/Jet')
├── Node('Mary/Udo/Dan/Jan')
└── Node('Mary/Udo/Dan/Joe')
Subtree rendering:
>>> print(RenderTree(marc))
Node('Mary/Udo/Marc')
└── Node('Mary/Udo/Marc/Lian')
Cut:
>>> dan.parent = None
>>> print(RenderTree(dan))
Node('Dan')
├── Node('Dan/Jet')
├── Node('Dan/Jan')
└── Node('Dan/Joe')
Installation
To install the anytree module run:
pip install anytree
If you do not have write-permissions to the python installation, try:
pip install anytree –user
Release files for anytree 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| anytree-0.0.1.tar.gz | 6.0 kB | Details |
Release files / anytree-0.0.1.tar.gz
| Download URL | anytree-0.0.1.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c44482110f751632cb97f317a7e01f6c23643336b95016db6f09bb46690d9861
|
|
BLAKE2b-256 checksum How to use checksums |
406f61183f744d60b8eb0b350955f8a22e3c76a36c3c54b7e48f48b39793508a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |