Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Print

Print It!

Overloads Python's print function to add new and exciting functionality.

Dependencies

  • Python3 (Python2 does not allow overloading of the print statement)
  • PyFiglet (ASII art, anyone?)

Installation

Install with

pip install printtools

For the latest version, clone this repository and use

python3 setup.py install

Usage

First, import * from print to get access to all constants. Then, call the print statement. The first argument is the object to print; all other arguments are treated as modifiers. For example:

>>> from print import *
>>> print("You can print normally")
You can print normally
>>> print(12345678)
12345678
>>> print("or with ASCII art", SM)
                  _ _   _        _   ___  ___ ___ ___            _
 ___ _ _  __ __ _(_) |_| |_     /_\ / __|/ __|_ _|_ _|  __ _ _ _| |_
/ _ \ '_| \ V  V / |  _| ' \   / _ \\__ \ (__ | | | |  / _` | '_|  _|
\___/_|    \_/\_/|_|\__|_||_| /_/ \_\___/\___|___|___| \__,_|_|  \__|

>>> print("you can combine attributes", RED, BLUE+BG, BOLD)
you can combine attributes

<this will be bold red on a blue background on supported systems>

Logging

Print comes with built-in logging. Use set_log to set the desired file, and lines will be appended:

from print import *

set_log('log.txt')
print('asdf')         # is appended to log.txt
print('Test', SLANT)  # is also appended to log.txt as ASCII art
print('Red', RED)     # ANSI escape sequences not written

To disable logging, set_log to None with set_log() or set_log(None).

Dividers

The div module can be used to create nice looking dividers:

>>> div.div('-')
----------------------------------------- # stretches all the way across the terminal
>>> div.div('*', 'Example')
** Example ******************************
>>> div.div('= =', 'Example')
=========================================

                Example

=========================================

Patterns include:

  • single character: repeats that character across the screen. If a message is provided, two characters are displayed, followed by a space, the message, a space, then characters occupying the remainder of the screen
  • character repeated, with spaces in between: draws two horizontal lines across the screens with that character; in between the two lines, the label text is drawn at the center. Blank lines equal to the number of spaces are added on top and below the label text.

Tables

Use the table module to print out tables. Tables consist of two-dimensional arrays:

>>> from print import *
>>> t = [["Entry 1", 0.0001, "Value 1"], ["Entry 2", 12345, "Value 2"]]
>>> table.table(t)
+-------+------+-------+
|Entry 1|0.0001|Value 1|
+-------+------+-------+
|Entry 2|12345 |Value 2|
+-------+------+-------+

table.render and render can be combined to add formatting:

>>> from print import *
>>> t = [
	[render("Entry 1", RED), 0.0001, "Value 1"],
	[render("Entry 2", GREEN), 12345, "Value 2"]]
>>> print(table.render(t), BOLD)

Custom Exception

Use the RenderedException class to provide a more colorful base exception class.

>>> class YouFuckedUpError(RenderedException):
...    pass
...
>>> raise YouFuckedUpError("You've really fucked it up this time. Yeah you.")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.YouFuckedUpError:
__   __        ___        _          _ _   _      ___
\ \ / /__ _  _| __|  _ __| |_____ __| | | | |_ __| __|_ _ _ _ ___ _ _
 \ V / _ \ || | _| || / _| / / -_) _` | |_| | '_ \ _|| '_| '_/ _ \ '_|
  |_|\___/\_,_|_| \_,_\__|_\_\___\__,_|\___/| .__/___|_| |_| \___/_|
                                            |_|
You've really fucked it up this time. Yeah you.

Constants

All constants are accessible with from print import * or by by calling print.<CONST>.

Basic formatting

RESET = 0
BOLD = 1
FAINT = 2
ITALIC = 3
UNDERLINE = 4
REVERSE = 7
CONCEAL = 8
STRIKEOUT = 9

Colors

BLACK = 30
RED = 31
GREEN = 32
YELLOW = 33
BLUE = 34
MAGENTA = 35
CYAN = 36
WHITE = 37

Modifiers

BRIGHT = 60
BR = 60
BACKGROUND = 10
BG = 10
  • BRIGHT / BR: use the brighter version of the color (not available on all terminals; your mileage may vary)
  • BACKGROUND / BG: set the background color instead of the text color

Fonts

Only these fonts are included as constants. Other Figlet fonts (see Figlet's website) can be passed as a string argument.

# Standard fonts
SM = "small"
STD = "standard"
BIG = "big"

# Isometric fonts
ISO1 = "isometric1"
ISO2 = "isometric2"
ISO3 = "isometric3"
ISO4 = "isometric4"

# Other fonts
SA = "contessa"
DOOM = "doom"
DP = "drpepper"
L3D = "larry3d"
SMISO = "smisome1"
KB = "smkeyboard"
SLANT = "slant"
SMSLANT = "smslant"

Metadata

Release files for printtools 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for printtools 1.2
File Size Uploaded Provenance Actions
printtools-1.2.tar.gz 7.4 kB Without provenance Details for printtools-1.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for printtools 1.2
File Interpreter ABI Platform Actions
printtools-1.2-py3.6.egg Legacy Egg format - - Details for printtools-1.2-py3.6.egg
printtools-1.2-py3-none-any.whl Python 3 none any Details for printtools-1.2-py3-none-any.whl
printtools-1.2-py2.7.egg Legacy Egg format - - Details for printtools-1.2-py2.7.egg

Total release size: 44.8 kB

Release files / printtools-1.2.tar.gz

Download URL printtools-1.2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6d851da3e79d93d2ae38736b6d2f9fee30cc4d1d18f7ed4a306d2bd1f7c4c05c
BLAKE2b-256 checksum
How to use checksums
93e2f67622c29a262c5222f59f43c707a395f71b5bfa375a3816db12273d4836
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

Release files / printtools-1.2-py3.6.egg

Download URL printtools-1.2-py3.6.egg
Size 17.3 kB
Tags Egg
SHA-256 checksum
How to use checksums
53b5e089e1fad658b96f3039b3f4473b1901d365b57e1004610bf70feec4a1f0
BLAKE2b-256 checksum
How to use checksums
85a60e540f4da1f67111d88ef070dfd98663ac6cc2696ab718d152565927d270
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

Release files / printtools-1.2-py3-none-any.whl

Download URL printtools-1.2-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30c707339e3950ae3cbd5cba4933a47b09a67eee8babe7931569e38e30e1e930
BLAKE2b-256 checksum
How to use checksums
bf223dc3c5a1c51a6e57f26131d184be6d5f8998864126dd35d4ee448b90a0c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

Release files / printtools-1.2-py2.7.egg

Download URL printtools-1.2-py2.7.egg
Size 10.3 kB
Tags Egg
SHA-256 checksum
How to use checksums
f0e010a9e9d691d60651ba9dbf7ce968946ac000d697880c51f1e3cff6894c3f
BLAKE2b-256 checksum
How to use checksums
ecdf1b42eec8f2717eb674c39495bb2b4011093eec35ef3d760bdcb0009bd810
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

Security for printtools 1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page