SEPPrinting

Color Printing

SEPPrinting.print_colors =True

Deprecated since version 2.1.1.

Global color printing control is now disabled.

SEPModules.SEPPrinting.color_string(s, style=AnsiControl((0, 'm')), *, boolean=False)

Add color ANSI escape sequences to a string. Longer name version of cl_s().

See also

Function cl_s() for documentation.

SEPModules.SEPPrinting.cl_s(s, style=AnsiControl((0, 'm')), *, boolean=False)

Add color ANSI escape sequences to a string. Shorter name version of color_string().

Parameters
  • s (Any) – object to convert to string (any type, but must implement __bool__ if boolean argument is set to True)

  • style (SEPModules.SEPPrinting.AnsiControl) – a AnsiControl instance

  • boolean (bool) – keyword only parameter, when set to True automatically formats the input as green or red string based on its boolean value

Returns

ANSI escape sequences of defined style(s) concatenated with str(s), where s may be of any type

Changed in version 2.1.1: Removed support for global print_colors attribute.

ANSI Control Sequences

class SEPModules.SEPPrinting.AnsiControl(*style)

AnsiControl represents ANSI control sequences and which actions can be performed on them. New AnsiControl objects may be instantiated using int ANSI CSI codes which will be combined as CSI int; or sequences of int, and str, which will be combined as CSI int0;int1;...;int_n str0. Furthermore, style can be combined into composite style by the bitwise & and | and the + operator. Strings (or bytes) can also be combined with styles, in which case strings (or bytes) concatenated with the entire control sequence will be returned.

Parameters

style (Union[int, Sequence[Union[int, str]]]) – an arbitrary amount of ANSI style codes

Printing Utilities

SEPModules.SEPPrinting.time_str(secs, n_digits=3, force_unit=None)

Helper function to format durations of times.

Parameters
  • secs (SupportsFloat) – seconds as number

  • n_digits (int) – the number of digits for floating point values in the output string

  • force_unit (Optional[Literal[ns, µs, ms, s, m, h]]) – can be str of value ns, µs, ms, s, m, or h to force a specific unit to display

Returns

formatted string with adequately chosen units

Raises
  • ValueError – if secs is negative

  • ValueError – if type of force_unit is not one of the specified literals

SEPModules.SEPPrinting.get_appropriate_time_unit(secs)

Turns a second value into a string of the appropriate unit.

See also

The literals returned by this function are compatible with time_str().

Parameters

secs (SupportsFloat) – seconds as integer or float

Returns

the unit-string determining the most appropriate unit for this seconds count

Return type

Literal[ns, µs, ms, s, m, h]

SEPModules.SEPPrinting.repr_str(obj, *properties, value_function=repr, include_none=False, include_empty_str=False, joiner=', ', **kwargs)

Provides a __repr__ string for any class using one instance of it.

Parameters
  • obj (Any) – the object to create this repr string from

  • properties (property[_T]) – the values which should be displayed in this repr string

  • value_function (Callable[[_T], str]) – which function to apply to each element of values

  • include_none (bool) – whether or not to include None values

  • include_empty_sized (bool) – whether or not to include empty Sized objects

  • include_empty_str (bool) – deprecated, whether or not to include empty strings

  • joiner (AnyStr) – which string to use to join the values together (see str.join())

  • kwargs (Any) – an arbitrary amount of keyword arguments to include in the final output string (of course excluding those keyword arguments, which are used in this function!)

Returns

a repr string for cls

Raises
  • NameError – if the given properties are not found in the class of obj

  • TypeError – if a type error is raised during retrieval of the value of the properties

Return type

str

SEPModules.SEPPrinting.error_str(original, error_from, error_to, error_msg=None, *, error_style=AnsiControl((31, 'm')), enable_color=True)