Skip to main content

Prints lists out as unicode trees.

Project description

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!! :]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unitrees-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unitrees-1.0.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file unitrees-1.0.0.tar.gz.

File metadata

  • Download URL: unitrees-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for unitrees-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b6781a3f5f760def5718b9d23dfd0d359ffbdbc56a6eca07e97784eeadcfb051
MD5 b2319bbd7668da18243abea26f2ccdbd
BLAKE2b-256 f4830de1cebadf683d251692256203d37a2121d7db1bf1608bb31d909fcb1889

See more details on using hashes here.

File details

Details for the file unitrees-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: unitrees-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for unitrees-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93536021a69b9aae2c13408d098541cd62149847334673c94927c8dee4e96d98
MD5 ce646fef4e3b4361cf174f5acf95153c
BLAKE2b-256 baa171305ce16e4ee258a1d46abbec2ecd6696e336970f08b60473a8db738559

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page