Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Printing Basics

Arguments are joined with semicolons

Multiple positional arguments are printed one after another, separated by a dim ; and a space:

import neoprint as np

np.show('Multiple', 'arguments', 'are', 'semicolon-separated')
np.show(123, 456, 'mixed types', True, False, None)

Semicolon-joined arguments

Booleans are highlighted: True is green, False is red, None is magenta.

If you want a different join style, pass :l (one value per line, see Expanded Formatting) or format the string yourself and pass a single argument.

Where to put a markup

A markup is a short string such as ':n', ':v8' or ':d2v7t' that changes how the message is rendered. Each character in it enables one feature; an optional digit selects a variant.

A markup is recognized in exactly two positions:

  1. as the first positional argument,
  2. as the last positional argument.
np.show(':d', 'Section title')          # first
np.show('Section title', ':d')          # last
np.show('Section title', markup=':d')   # keyword

Anything else is treated as ordinary text:

np.show('a', ':n', 'b')   # ':n' is printed literally
main.py:1   | a; :n; b

The string must look like a markup to be treated as one: it has to start with : and contain only the known mark letters. Something like ':)' or ': not a markup' is plain text.

Combining marks

Marks can be stacked in a single string. Each mark letter may carry at most one digit:

np.show(':d2v7t', 'End')
main.py:1   | [16:57:41 -> 16:57:41 (4ms)] ██████████ End ██████████

Read it as :d2 + :v7 + :t. Order does not matter.

Bare marks and their defaults

Writing a mark without a digit selects its default variant. For example :i is :i1 and :e is :e2:

MarkBare form means
:d:d1 thin divider
:e:e2 traceback panel
:i:i1 line-level counter
:l:l1 expanded format
:n:n1 show variable names
:p:p1 parent frame
:r:r1 inline markup enabled
:s:s1 short form
:t:t2 time since last mark
:v:v0 debug level

The full list is in Markup Reference.

Quiet and plain modes

Two marks reduce or remove neoprint’s decoration:

  • :s1 keeps colors but drops the source head and variable names.
  • :s2 hands the arguments to the built-in print untouched.
np.show(':s1', 'no source, no varnames')
np.show(':s2', 'built-in print behaviour')
no source, no varnames
built-in print behaviour

:s2 is handy when a call must accept the same keyword arguments as the built-in print (for example file=sys.stderr).

A note on string formatting

Neoprint follows the convention of this project: prefer str.format over f-strings, because f-strings in log calls are evaluated even when the output is filtered by verbosity.

np.show(':v1', 'loaded {} items'.format(count))

Next: How Markup Works.