asaptools.vprinter module

A module containing the VPrinter class.

This module contains the VPrinter class that enables clean printing to standard out (or a string) with verbosity-level print management.

Copyright 2020 University Corporation for Atmospheric Research

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class asaptools.vprinter.VPrinter(header='', verbosity=1)[source]

Bases: object

A Verbosity-enabled Printing Class.

The VPrinter is designed to print messages to standard out, or optionally a string, as determined by a pre-set verbosity-level and/or on which parallel rank the VPrinter is instantiated.

header

A string to prepend to any print messages before they are printed

Type

str

verbosity

The verbosity level to use when determining if a message should be printed

Type

int

to_str(*args, **kwargs)[source]

Concatenates string representations of the input arguments.

This takes a list of arguments of any length, converts each argument to a string representation, and concatenates them into a single string.

Parameters

args (list) – A list of arguments supplied to the function. All of these arguments will be concatenated together.

Keyword Arguments

kwargs (dict) – The dictionary of keyword arguments passed to the function.

Returns

A single string with the arguments given converted to strings

and concatenated together (in order). If the keyword ‘header==True’ is supplied, then the ‘header’ string is prepended to the string before being output.

Return type

str

Raises

TypeError – If the ‘header’ keyword argument is supplied and is not a bool