ATLAS Offline Software
Functions | Variables
python.ext.table_printer Namespace Reference

Functions

def format_num (num)
 
def get_max_width (table, index)
 
def pprint_table_to (out, table, header_loc=1)
 
def pprint_table (table, header_loc=1)
 
def pprint_table_string (table, header_loc=1)
 

Variables

string __version__ = "0.1"
 
string __author__ = "Ryan Ginstrom"
 
list table
 

Function Documentation

◆ format_num()

def python.ext.table_printer.format_num (   num)
Format a number according to given places.
Adds commas, etc.

Definition at line 28 of file table_printer.py.

28 def format_num(num):
29  """Format a number according to given places.
30  Adds commas, etc."""
31  from builtins import int
32  if isinstance(num, int):
33  return splitThousands(num)
34 
35  return str(num)
36 

◆ get_max_width()

def python.ext.table_printer.get_max_width (   table,
  index 
)
Get the maximum width of the given column index

Definition at line 37 of file table_printer.py.

37 def get_max_width(table, index):
38  """Get the maximum width of the given column index
39  """
40 
41  return max([len(format_num(row[index])) for row in table])
42 

◆ pprint_table()

def python.ext.table_printer.pprint_table (   table,
  header_loc = 1 
)

Definition at line 68 of file table_printer.py.

68 def pprint_table(table, header_loc=1):
69  pprint_table_to(sys.stdout, table, header_loc)
70 

◆ pprint_table_string()

def python.ext.table_printer.pprint_table_string (   table,
  header_loc = 1 
)

Definition at line 71 of file table_printer.py.

71 def pprint_table_string(table, header_loc=1):
72  from cStringIO import StringIO
73  sio = StringIO()
74  pprint_table_to(sio, table, header_loc)
75  return sio.getvalue()
76 

◆ pprint_table_to()

def python.ext.table_printer.pprint_table_to (   out,
  table,
  header_loc = 1 
)
Prints out a table of data, padded for alignment

@param out: Output stream ("file-like object")
@param table: The table to print. A list of lists. Each row must have the same
number of columns.

Definition at line 43 of file table_printer.py.

43 def pprint_table_to(out, table, header_loc=1):
44  """Prints out a table of data, padded for alignment
45 
46  @param out: Output stream ("file-like object")
47  @param table: The table to print. A list of lists. Each row must have the same
48  number of columns.
49 
50  """
51 
52  col_paddings = []
53 
54  for i in range(len(table[0])):
55  col_paddings.append(get_max_width(table, i))
56 
57  for i, row in enumerate(table):
58  if i == header_loc:
59  print("-" * (sum(col_paddings) + (len(col_paddings)*3-1)), end='', file=out)
60  # left col
61  print(row[0].ljust(col_paddings[0] + 2), end='', file=out)
62  # rest of the cols
63  for i in range(1, len(row)):
64  col = format_num(row[i]).rjust(col_paddings[i] + 2)
65  print(col, end='', file=out)
66  print(file=out)
67 

Variable Documentation

◆ __author__

string python.ext.table_printer.__author__ = "Ryan Ginstrom"
private

Definition at line 22 of file table_printer.py.

◆ __version__

string python.ext.table_printer.__version__ = "0.1"
private

Definition at line 21 of file table_printer.py.

◆ table

list python.ext.table_printer.table
Initial value:
1 = [["", "taste", "land speed", "life"],
2  ["spam", 300101, 4, 1003],
3  ["eggs", 105, 13, 42],
4  ["lumberjacks", 13, 105, 10]]

Definition at line 78 of file table_printer.py.

python.ext.table_printer.pprint_table
def pprint_table(table, header_loc=1)
Definition: table_printer.py:68
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
python.ext.table_printer.get_max_width
def get_max_width(table, index)
Definition: table_printer.py:37
python.ext.table_printer.pprint_table_string
def pprint_table_string(table, header_loc=1)
Definition: table_printer.py:71
python.ext.table_printer.format_num
def format_num(num)
Definition: table_printer.py:28
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
python.ext.thousands.splitThousands
def splitThousands(s, tSep=',', dSep='.')
Definition: thousands.py:12
python.ext.table_printer.pprint_table_to
def pprint_table_to(out, table, header_loc=1)
Definition: table_printer.py:43
str
Definition: BTagTrackIpAccessor.cxx:11