cloudmesh-common.cloudmesh.common.Printer
¶
Convenient methods and classes to print tables.
Module Contents¶
Classes¶
A simple Printer class with convenient methods to print dictionary, tables, csv, lists |
-
class
cloudmesh-common.cloudmesh.common.Printer.
Printer
¶ Bases:
object
A simple Printer class with convenient methods to print dictionary, tables, csv, lists
-
classmethod
flatwrite
(cls, table, order=None, header=None, output='table', sort_keys=True, show_none='', humanize=None, sep='.', max_width=48)¶ writes the information given in the table :param table: the table of values :param order: the order of the columns :param header: the header for the columns :param output: the format (default is table, values are raw, csv, json, yaml, dict :param sort_keys: if true the table is sorted :param show_none: passed along to the list or dict printer :param sep: uses sep as the separator for csv printer :param max_width: maximum width for a cell :type max_width: int :return:
-
classmethod
write
(cls, table, order=None, header=None, output='table', sort_keys=True, humanize=None, show_none='', max_width=48)¶ writes the information given in the table :param table: the table of values :param order: the order of the columns :param header: the header for the columns :param output: the format (default is table, values are raw, csv, json, yaml, dict :param sort_keys: if true the table is sorted :param show_none: passed along to the list or dict printer :param max_width: maximum width for a cell :type max_width: int :return:
-
classmethod
list
(cls, l, order=None, header=None, output='table', sort_keys=True, humanize=None, show_none='', max_width=48)¶ - Parameters
l – l is a list not a dict
order –
header –
output –
sort_keys –
show_none –
max_width (int) – maximum width for a cell
- Returns
-
classmethod
dict
(cls, d, order=None, header=None, output='table', sort_keys=True, humanize=None, show_none='', max_width=48)¶ - Parameters
d (dict) – A a dict with dicts of the same type.
order (list) – The order in which the columns are printed. The order is specified by the key names of the dict.
header (list or tuple of field names) – The Header of each of the columns
output (string) – type of output (table, csv, json, yaml or dict)
sort_keys (bool) – list
show_none (string) – prints None if True for None values otherwise “”
max_width (int) – maximum width for a cell
- Returns
-
classmethod
csv
(cls, d, order=None, header=None, humanize=None, sort_keys=True)¶ prints a table in csv format
- Parameters
d (dict) – A a dict with dicts of the same type.
order – The order in which the columns are printed. The order is specified by the key names of the dict.
header (list or tuple of field names) – The Header of each of the columns
sort_keys (bool) – TODO - not yet implemented
- Returns
a string representing the table in csv format
-
classmethod
dict_html
(cls, d, order=None, header=None, sort_keys=True, show_none='', humanize=None, max_width=48)¶
-
classmethod
dict_table
(cls, d, order=None, header=None, sort_keys=True, show_none='', humanize=None, max_width=48)¶ prints a pretty table from an dict of dicts
- Parameters
d – A a dict with dicts of the same type. Each key will be a column
order – The order in which the columns are printed. The order is specified by the key names of the dict.
header (A list of string) – The Header of each of the columns
sort_keys (string or a tuple of string (for sorting with multiple columns)) – Key(s) of the dict to be used for sorting. This specify the column(s) in the table for sorting.
show_none (string) – prints None if True for None values
max_width (int) – maximum width for a cell
-
classmethod
attribute
(cls, d, header=None, order=None, sort_keys=True, humanize=None, output='table')¶ prints a attribute/key value table
- Parameters
d – A a dict with dicts of the same type. Each key will be a column
order – The order in which the columns are printed. The order is specified by the key names of the dict.
header (A list of string) – The Header of each of the columns
sort_keys (string or a tuple of string (for sorting with multiple columns)) – Key(s) of the dict to be used for sorting. This specify the column(s) in the table for sorting.
output – the output format table, csv, dict, json
-
classmethod
print_list
(cls, l, output='table')¶ prints a list :param l: the list :param output: the output, default is a table :return:
-
classmethod
row_table
(cls, d, order=None, labels=None)¶ prints a pretty table from data in the dict.
- Parameters
d – A dict to be printed
order – The order in which the columns are printed. The order is specified by the key names of the dict.
labels – The array of labels for the column
-
classmethod