Skip to content

Output

clo.output

Output handler

clo.output.Levels

Bases: Enum

An enumerator representing log levels.

clo.output.Levels.OFF class-attribute instance-attribute

OFF = 0

Disables all logging.

clo.output.Levels.FATAL class-attribute instance-attribute

FATAL = 1

Logs when an error causes the program to abort.

clo.output.Levels.ERROR class-attribute instance-attribute

ERROR = 2

Logs when the program has a non-fatal error.

clo.output.Levels.WARN class-attribute instance-attribute

WARN = 3

Logs when the program needs to warn the user of something.

clo.output.Levels.INFO class-attribute instance-attribute

INFO = 4

Logs general information.

clo.output.Levels.DEBUG class-attribute instance-attribute

DEBUG = 5

Logs verbose, debugging infromation.

clo.output.Levels.TRACE class-attribute instance-attribute

TRACE = 6

Logs egregiously verbos infromation.

clo.output.Log

A singleton class for outputting logs to stderr.

clo.output.Log.FATAL classmethod

FATAL(*values, sep=' ', end='\n', flush=False, code=10)

Output a FATAL-level log.

PARAMETER DESCRIPTION
sep

A string inserted between values.

TYPE: str | None DEFAULT: ' '

end

A string appended after the last value.

TYPE: str | None DEFAULT: '\n'

flush

Whether to forcibly flush the stream.

TYPE: bool DEFAULT: False

code

If set, calls for exit with the code specified.

TYPE: int DEFAULT: 10

clo.output.Log.ERROR classmethod

ERROR(*values, sep=' ', end='\n', flush=False, code=10)

Output an ERROR-level log.

PARAMETER DESCRIPTION
sep

A string inserted between values.

TYPE: str | None DEFAULT: ' '

end

A string appended after the last value.

TYPE: str | None DEFAULT: '\n'

flush

Whether to forcibly flush the stream.

TYPE: bool DEFAULT: False

code

If set, calls for exit with the code specified.

TYPE: int DEFAULT: 10

clo.output.Log.WARN classmethod

WARN(*values, sep=' ', end='\n', flush=False)

Output a WARN-level log.

PARAMETER DESCRIPTION
sep

A string inserted between values.

TYPE: str | None DEFAULT: ' '

end

A string appended after the last value.

TYPE: str | None DEFAULT: '\n'

flush

Whether to forcibly flush the stream.

TYPE: bool DEFAULT: False

clo.output.Log.INFO classmethod

INFO(*values, sep=' ', end='\n', flush=False)

Output an INFO-level log.

PARAMETER DESCRIPTION
sep

A string inserted between values.

TYPE: str | None DEFAULT: ' '

end

A string appended after the last value.

TYPE: str | None DEFAULT: '\n'

flush

Whether to forcibly flush the stream.

TYPE: bool DEFAULT: False

clo.output.Log.DEBUG classmethod

DEBUG(*values, sep=' ', end='\n', flush=False)

Output a DEBUG-level log.

PARAMETER DESCRIPTION
sep

A string inserted between values.

TYPE: str | None DEFAULT: ' '

end

A string appended after the last value.

TYPE: str | None DEFAULT: '\n'

flush

Whether to forcibly flush the stream.

TYPE: bool DEFAULT: False

clo.output.Log.TRACE classmethod

TRACE(*values, sep=' ', end='\n', flush=False)

Output a TRACE-level log.

PARAMETER DESCRIPTION
sep

A string inserted between values.

TYPE: str | None DEFAULT: ' '

end

A string appended after the last value.

TYPE: str | None DEFAULT: '\n'

flush

Whether to forcibly flush the stream.

TYPE: bool DEFAULT: False

clo.output.ToJSON

ToJSON(obj)

Convert a serializable object into JSON.

PARAMETER DESCRIPTION
obj

Any serializable object.

TYPE: Any

RETURNS DESCRIPTION
str

A JSON-formatted document.

TYPE: str

clo.output.ToCSV

ToCSV(records, file, sep=',')

Write a list of records to CSV.

PARAMETER DESCRIPTION
records

A list of records.

TYPE: list[dict[str, Any]]

file

The stream the output will be saved to.

TYPE: TextIOWrapper

sep

The column separator.

TYPE: str DEFAULT: ','

clo.output.FromCSV

FromCSV(file, sep=',')

Convert CSV file contents into a list of records.

PARAMETER DESCRIPTION
file

The CSV-formatted input file.

TYPE: TextIOWrapper

sep

The separator used in the file.

TYPE: str DEFAULT: ','

RETURNS DESCRIPTION
list[dict[str, Any]]

list[dict[str, Any]]: A list of records.

clo.output.Columnize

Columnize(items, width=120, *, border=3, spacing=' ', end='\n')

Formats a set of subject/details pairs.

PARAMETER DESCRIPTION
items

The items to format.

TYPE: list[tuple[str, str]]

border

The size of spacing between the subject and details.

TYPE: int DEFAULT: 3

end

A suffix to append to each pair-rendering.

TYPE: str DEFAULT: '\n'

RETURNS DESCRIPTION
str

The formatted text.

TYPE: str