Introduction
Unitrees is a very simple Python module for printing out little text "trees" generated from lists, turning out to look rather like this:
Note that the font on PyPi may affect the way this is seen. If all goes well, it should be perfect, but online it may not be. However, the following text, when viewed in the terminal/shell, should be devoid of gaps between the lines.
\
┐
├─A
├─B
├─C
├┐
│├─D
│├─E
│├┐
││├─F
││├─G
││├┐
│││├─H
││├┘
│├┘
│├─I
├┘
... [shortened for clarity] ...
├─O
├─P
┘
Usage
This module is incredibly easy to use. It has three main functions; visual_standard(...), visual_space(...), and visual_ascii(...). It comes with multiple character sets (in list form), that can be plugged into the visual_standard(...) function. Here is a list of the character sets:
- characters_thick
- characters_thin
- characters_unicode
- characters_alt
- characters_dubl
- characters_audiowaves
Each character set has it's own style. The style used for the demonstration tree was characters_thin, the default option (it looks the best on a mac - if you are using windows, characters_thick may look better). In order to generate a tree using one of the character sets, you simply have to type the following python line into a python shell:
>>> unitrees.visual_standard(<your list, eg. ['A', ['A, 'B', ['C']], 'D']>, charset=unitrees.characters_thin)
This command will print out a unicode tree.
visual_space(...) & visual_ascii(...)
If you would like to have an ascii tree, you can either use the characters_unicode character set or use the specalised function. Furthermore, if you would like a tree puerly based off indention, you may use the visual_space(...) function.
Technical ⚙️
Creating your own character sets
It is actually quite easy to create your own character sets; all you have to do is define a five character list containing all the symbols that the function might request. The list used for characters_thin is shown below:
characters_thin = [
'├', '┐', '┘', '│', '─'
]
\
The first item in the list is used as a junction between the main line and either a sub-line or a text snippet. An example of this section in the tree is shown below:
├ ─ A
Note that the characters have a space between them for clarity.
As also shown above, the last character in the list adds as a "cross beam" of sorts, seperating the letter form the junction.
The second character acts as a sub-tree start symbol, and can also be found at the begining of the tree. The text snippet below shows this:
├┐
│├─D
The third also acts as a terminator for a sub-tree, and the overall main tree:
│├─I
├┘
The fourth character does not seem very important, but it is actually cruital - it continues through to show depth when a sub-tree is being displyed. An example is shown below:
├┐
│├─D
│├─E
│├┐
││├─F
││├─G
││├┐
│││├─H
││├┘
│├┘
│├─I
├┘
Tip: If you cannot see what I mean, look at the first character of every line. That line is unbroken while the sub-tree is being printed. That is the fourth character in every list.
Credits
Credits go to:
Pigeon Nation!! :]
Release files for unitrees 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| unitrees-1.0.0.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| unitrees-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / unitrees-1.0.0.tar.gz
| Download URL | unitrees-1.0.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6781a3f5f760def5718b9d23dfd0d359ffbdbc56a6eca07e97784eeadcfb051
|
|
BLAKE2b-256 checksum How to use checksums |
f4830de1cebadf683d251692256203d37a2121d7db1bf1608bb31d909fcb1889
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / unitrees-1.0.0-py3-none-any.whl
| Download URL | unitrees-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93536021a69b9aae2c13408d098541cd62149847334673c94927c8dee4e96d98
|
|
BLAKE2b-256 checksum How to use checksums |
baa171305ce16e4ee258a1d46abbec2ecd6696e336970f08b60473a8db738559
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|