test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
tablePrinter Namespace Reference

Functions

def indent
 

Variables

string data
 
int headerwidth = 46
 
tuple labels = ('First Name','Last Name','Age','Position')
 
list lumidata
 
list lumifooter = [('%-*s'%(24,'189'),'%-*s'%(10,'17.89'),'%-*s'%(10,'16.1'),'%-*s'%(20,'3.47'))]
 
list lumiheader = [('%-*s'%(30,'Lumi Sections'),'%-*s'%(46,'Luminosity'))]
 
list rows = [row.strip().split(',') for row in data.splitlines()]
 
int width = 10
 

Function Documentation

def tablePrinter.indent (   rows,
  hasHeader = False,
  headerChar = '-',
  delim = ' | ',
  justify = 'center',
  separateRows = False,
  prefix = '',
  postfix = '',
  wrapfunc = lambda x:x 
)
Indents a table by column.
- rows: A sequence of sequences of items, one sequence per row.
- hadHeader: True if the first row consists of the column's names.
- headerChar: Character to be used for the row separator line
(if hasHeader==True or separateRows==True).
- delim: The column delimiter.
- justify: Determines how are data justified in their column.
Valid values are 'left','right','center'.
- separateRows: True if rows are to be separated by a line of 'headerChar's.
- prefix: A string prepended to each printed row.
- postfix: A string appended to each printed row.
- wrapfunc: A function f(text) for wrapping text; each element in the table is first wrapped by this function.

Definition at line 9 of file tablePrinter.py.

References bookConverter.max, split, and ComparisonHelper.zip().

9 
10  separateRows=False,prefix='',postfix='',wrapfunc=lambda x:x):
11  """
12  Indents a table by column.
13  - rows: A sequence of sequences of items, one sequence per row.
14  - hadHeader: True if the first row consists of the column's names.
15  - headerChar: Character to be used for the row separator line
16  (if hasHeader==True or separateRows==True).
17  - delim: The column delimiter.
18  - justify: Determines how are data justified in their column.
19  Valid values are 'left','right','center'.
20  - separateRows: True if rows are to be separated by a line of 'headerChar's.
21  - prefix: A string prepended to each printed row.
22  - postfix: A string appended to each printed row.
23  - wrapfunc: A function f(text) for wrapping text; each element in the table is first wrapped by this function.
24  """
25  #nested function
26  #closure for breaking logical rows to physical, using wrapfunc
27  def rowWrapper(row):
28  newRows=[wrapfunc(item).split('\n') for item in row]
29  #print 'newRows: ',newRows
30  #print 'map result: ',map(None,*newRows)
31  #print 'rowwrapped: ',[[substr or '' for substr in item] for item in map(None,*newRows)]
32  return [[substr or '' for substr in item] for item in map(None,*newRows)]
33  # break each logical row into one or more physical ones
34  logicalRows = [rowWrapper(row) for row in rows]
35  # columns of physical rows
36  columns = map(None,*reduce(operator.add,logicalRows))
37  # get the maximum of each column by the string length of its items
38  maxWidths = [max([len(str(item)) for item in column]) for column in columns]
39  rowSeparator = headerChar * (len(prefix) + len(postfix) + sum(maxWidths) + len(delim)*(len(maxWidths)-1))
40  # select the appropriate justify method
41  justify = {'center':str.center,'right':str.rjust,'left':str.ljust}[justify.lower()]
42  output=cStringIO.StringIO()
43  if separateRows: print >> output,rowSeparator
44  for physicalRows in logicalRows:
45  for row in physicalRows:
46  print >> output, prefix+delim.join([justify(str(item),width) for (item,width) in zip(row,maxWidths)])+postfix
47  if separateRows or hasHeader: print >> output, rowSeparator; hasHeader=False
48  return output.getvalue()
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
double split
Definition: MVATrainer.cc:139

Variable Documentation

string tablePrinter.data
Initial value:
1 = """John,Smith,24,Software Engineer
2  Mary,Brohowski,23,Sales Manager
3  Aristidis,Papageorgopoulos,28,Senior Reseacher"""

Definition at line 52 of file tablePrinter.py.

int tablePrinter.headerwidth = 46

Definition at line 72 of file tablePrinter.py.

tuple tablePrinter.labels = ('First Name','Last Name','Age','Position')

Definition at line 51 of file tablePrinter.py.

list tablePrinter.lumidata
Initial value:
1 = [\
2  ('%-*s'%(8,'run'),'%-*s'%(8,'first'),'%-*s'%(8,'last'),'%-*s'%(10,'delivered'),'%-*s'%(10,'recorded'),'%-*s'%(20,'recorded\nmypathdfdafddafd')),\
3  ['%d'%(132440),'%d'%(23),'%d'%(99),'%.2f'%(2.345),'%.2f'%(1.23),'%.2f'%(0.5678)],\
4  ['%d'%(132442),'%d'%(1),'%d'%(20),'%.2f'%(2.345),'%.2f'%(1.23),'%.2f'%(0.5678)],\
5  ['','%d'%(27),'%d'%(43),'%.2f'%(2.345),'%.2f'%(1.23),'%.2f'%(0.5678)]\
6  ]

Definition at line 65 of file tablePrinter.py.

list tablePrinter.lumifooter = [('%-*s'%(24,'189'),'%-*s'%(10,'17.89'),'%-*s'%(10,'16.1'),'%-*s'%(20,'3.47'))]

Definition at line 74 of file tablePrinter.py.

list tablePrinter.lumiheader = [('%-*s'%(30,'Lumi Sections'),'%-*s'%(46,'Luminosity'))]

Definition at line 71 of file tablePrinter.py.

Referenced by lumi::Lumi2DB.retrieveData().

list tablePrinter.rows = [row.strip().split(',') for row in data.splitlines()]

Definition at line 55 of file tablePrinter.py.

Referenced by SiPixelRecHitsValid.fillBarrel(), SiPixelRecHitsValid.fillForward(), SiPixelActionExecutor.fillSummary(), pos::PixelCalibConfiguration.PixelCalibConfiguration(), presort(), presort_egamma(), MuonResidualsFitter.read(), FWTEveViewer.SaveJpg(), FWTEveViewer.SavePng(), SiPixelCalibConfiguration.SiPixelCalibConfiguration(), and MuonResidualsFitter.write().

int tablePrinter.width = 10

Definition at line 60 of file tablePrinter.py.