corelp.print module

corelp.print(string, verbose: bool = None, *, return_string=False, file=None, mode='a', end='\n', **kwargs)

Enhanced replacement for the built-in print() function, adding muting, logging, rich formatting, and progress utilities.

This class is callable and behaves like print(), with extra arguments.

Parameters:
  • string (object) – The object to print. Its __str__() representation is used.

  • verbose (bool, optional) – If True (default), printing is performed. If False, printing is skipped unless overridden.

  • return_string (bool, optional) – If True, return the processed string instead of None.

  • file (str or pathlib.Path or None, optional) – If provided, overrides the configured log file.

  • mode ({"w", "a"}, optional) – File mode used when writing logs. Default is "a".

  • end (str, optional) – End-of-line character(s). Defaults to "\n".

  • **kwargs – Additional keyword arguments passed to print() or Rich’s Console.print().

Examples

Basic usage:

>>> from corelp import print
>>> s = "Hello *world*!\nThis is a print **example**"
>>> print(s)

Muting:

>>> print.verbose = False
>>> print(s)                 # muted
>>> print(s, verbose=True)   # forced printing
>>> print.verbose = True
>>> print(s)                 # prints again
>>> print(s, verbose=False)  # forced mute

Access to underlying print functions:

>>> print.pyprint(s)   # built-in print
>>> print.richprint(s) # rich.print
>>> print.print(s)     # Console.print
>>> print.log(s)       # Console.log

Logging:

>>> print.file = "log.txt"
>>> print("Hello")     # also writes to file

Console styling:

>>> print.theme = {"success": "green"}
>>> print("Done!", style="success")
>>> try:
...     1/0
... except Exception:
...     print.error()
>>> print.export_html("log.html")

Progress / Clock:

>>> from time import sleep
>>> for i in print.clock(15, "Outer"):
...     for j in print.clock(10, "Inner"):
...         sleep(1)
corelp.verbose

Global muting switch.

Type:

bool

corelp.pyprint

Built-in Python print().

Type:

callable

corelp.richprint

rich print function.

Type:

callable

corelp.console

The Rich console instance used for styled printing.

Type:

rich.console.Console

corelp.file

Path to the log file.

Type:

pathlib.Path or None

corelp.progress

Active Rich progress manager.

Type:

rich.progress.Progress

corelp.bars

Dictionary storing active progress bars.

Type:

dict

corelp.theme

Custom Rich style definitions.

Type:

dict