Belle II Software development
TablePrinter Class Reference

Public Member Functions

 __init__ (self, ncols, width=None)
 
 tot_width (self)
 
 print_divider (self, char="=")
 
 print (self, cols)
 

Public Attributes

 ncols = ncols
 the number of columns
 
list widths = [width] * ncols
 width of each column
 

Detailed Description

 A tiny class to print columns of fixed width numbers. 

Definition at line 713 of file validationcomparison.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
ncols,
width = None )
Constructor.
@param ncols: Number of columns
@param width: Width of each column. Either int or list.

Definition at line 716 of file validationcomparison.py.

716 def __init__(self, ncols, width=None):
717 """
718 Constructor.
719 @param ncols: Number of columns
720 @param width: Width of each column. Either int or list.
721 """
722
723 self.ncols = ncols
724 if not width:
725 width = 10
726 if isinstance(width, int):
727
728 self.widths = [width] * ncols
729 elif isinstance(width, list) or isinstance(width, tuple):
730 # let's hope this is a list then.
731 self.widths = width
732

Member Function Documentation

◆ print()

print ( self,
cols )
 Print one row 

Definition at line 751 of file validationcomparison.py.

751 def print(self, cols):
752 """ Print one row """
753 assert len(cols) == self.ncols
754 out = []
755 for icol, col in enumerate(cols):
756 width = self.widths[icol]
757 if isinstance(col, int):
758 form = f"{{:{width}d}}"
759 out.append(form.format(col))
760 elif isinstance(col, float):
761 form = f"{{:{width}.{width // 2}f}}"
762 out.append(form.format(col))
763 else:
764 # convert everything else to a string if it isn't already
765 col = str(col)
766 col = col[:width].rjust(width)
767 out.append(col)
768 print("| " + " | ".join(out) + " |")
769
770

◆ print_divider()

print_divider ( self,
char = "=" )
 Print a divider made up from repeated chars 

Definition at line 745 of file validationcomparison.py.

745 def print_divider(self, char="="):
746 """ Print a divider made up from repeated chars """
747 # \cond false positive doxygen warning
748 print(char * self.tot_width)
749 # \endcond
750

◆ tot_width()

tot_width ( self)
 Total width of the table 

Definition at line 734 of file validationcomparison.py.

734 def tot_width(self):
735 """ Total width of the table """
736 width = 0
737 # the widths of each column
738 width += sum(self.widths)
739 # three characters between each two columns
740 width += (self.ncols - 1) * 3
741 # 2 characters at the very left and right
742 width += 2 * 2
743 return width
744

Member Data Documentation

◆ ncols

ncols = ncols

the number of columns

Definition at line 723 of file validationcomparison.py.

◆ widths

list widths = [width] * ncols

width of each column

Definition at line 728 of file validationcomparison.py.


The documentation for this class was generated from the following file: