Internal subroutines for e.g. aborting execution with an error message, or performing indenting on multiline output.
Abort execution, print
msgto stderr and exit with error status (1.)
Therefore, it’s possible to detect and recover from inner calls to
except SystemExitor similar.
error(message, func=None, exception=None, stdout=None, stderr=None)¶
funcwith given error
funcis None (the default), the value of
env.warn_onlydetermines whether to call
exceptionis given, it is inspected to get a string message, which is printed alongside the user-generated
stderrare given, they are assumed to be strings to be printed.
fastprint(text, show_prefix=False, end='', flush=True)¶
textimmediately, without any prefix or line ending.
This function is simply an alias of
putswith different default argument values, such that the
textis printed without any embellishment and immediately flushed.
It is useful for any situation where you wish to print text which might otherwise get buffered by Python’s output buffering (such as within a processor intensive
forloop). Since such use cases typically also require a lack of line endings (such as printing a series of dots to signify progress) it also omits the traditional newline by default.
New in version 0.9.2.
indent(text, spaces=4, strip=False)¶
textindented by the given number of spaces.
If text is not a string, it is assumed to be a list of lines and will be joined by
\nprior to indenting.
True, a minimum amount of whitespace is removed from the left-hand side of the given string (so that relative indents are preserved, but otherwise things are left-stripped). This allows you to effectively “normalize” any previous indentation for some inputs.
Check if a stream is a tty.
Not all file-like objects implement the
puts(text, show_prefix=None, end='\n', flush=False)¶
An alias for
In other words, this function simply prints to
sys.stdout, but will hide its output if the
useroutput level is set to
putswill omit the leading
[hostname]which it tacks on by default. (It will also omit this prefix if
Newlines may be disabled by setting
endto the empty string (
''). (This intentionally mirrors Python 3’s
You may force output flushing (e.g. to bypass output buffering) by setting
New in version 0.9.2.