Skip to content

Commit 6ccac36

Browse files
committed
add print table title for base class
1 parent 2b70154 commit 6ccac36

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tools/analysis/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,22 @@ def getherDataToArray(self):
314314
icol += ncols
315315
return dat_out
316316

317-
def printTable(self, column_format):
317+
def printTable(self, column_format, print_title=True):
318318
"""
319319
print Table with defined column list and formats
320320
321321
Parameters
322322
column_format: a list of column label (class member name) and format, enclosed by tuple, for sub-member, use . to access
323323
For exmaple: [(key1,'%s'), (key2,'%12.7f'), (key3.subkey1,'%d'), (key3.subkey2,'%e')]
324+
print_title: print title of keys (default: True)
324325
"""
326+
import re
327+
325328
if self.size==0: return
329+
title=[]
326330
table=[]
327331
fmt_list=''
332+
fmt_title=''
328333
for key, fmt in column_format:
329334
keylst = key.split('.')
330335
dat_key=self
@@ -335,9 +340,16 @@ def printTable(self, column_format):
335340
dat_key = dat_key[key_name][:,index]
336341
else:
337342
dat_key = dat_key[ikey]
343+
title.append(key)
344+
if '.' in fmt:
345+
fmt_title += re.sub('\.[0-9]*[a-zA-Z]','s',fmt)
346+
else:
347+
fmt_title += re.sub('[a-zA-Z]','s',fmt)
338348
table.append(dat_key)
339349
fmt_list += fmt
340350
table=np.transpose(np.array(table))
351+
if (print_title):
352+
print(fmt_title % tuple(title))
341353
for line in table:
342354
print(fmt_list % tuple(line))
343355

0 commit comments

Comments
 (0)