|
1 |
| -from __future__ import print_function, unicode_literals |
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
2 | 3 |
|
| 4 | +from __future__ import print_function, unicode_literals |
| 5 | +from .exceptions import SupressedError |
3 | 6 |
|
4 | 7 | class Table():
|
5 | 8 | """docstring for Table.
|
6 | 9 | This is the main class. It adds rows and columns, with data
|
7 | 10 | """
|
8 |
| - def __init__(self, name): |
| 11 | + def __init__(self, name, debug = True): |
9 | 12 | super(Table, self).__init__()
|
| 13 | + self.debug = debug |
10 | 14 | self.rows = 0
|
11 | 15 | self.columns = 1
|
12 | 16 | self.table = '''|{}|'''.format(str(name))
|
13 | 17 | self.finalized = False
|
| 18 | + if self.debug: |
| 19 | + self.functions = [] |
14 | 20 |
|
15 | 21 | def debug(self):
|
16 |
| - print('''Printing debug information: |
17 |
| - Rows: {rows} |
18 |
| - Columns: {cols} |
19 |
| - Finalized?: {fin} |
20 |
| - Table Content: {table}'''.format(rows = str(self.rows), |
21 |
| - cols = str(self.columns), |
22 |
| - fin = str(self.finalized), |
23 |
| - table = self.table)) |
| 22 | + try: |
| 23 | + print('''Printing debug information: |
| 24 | + Rows: {rows} |
| 25 | + Columns: {cols} |
| 26 | + Finalized?: {fin} |
| 27 | + Table Content: {table} |
| 28 | + Functions: {funcs}'''.format(rows = str(self.rows), |
| 29 | + cols = str(self.columns), |
| 30 | + fin = str(self.finalized), |
| 31 | + table = self.table, |
| 32 | + funcs = self.functions)) |
| 33 | + except(NameError): |
| 34 | + pass |
| 35 | + except Exception as e: |
24 | 36 |
|
25 |
| - def add_column(self, name): |
| 37 | + def add_column(self, name, all_cols = False): |
26 | 38 | self.columns += 1
|
27 |
| - self.table += '''{}|'''.format(name) |
| 39 | + self.table += '{}|'.format(str(name)) |
| 40 | + try: |
| 41 | + if all_cols: |
| 42 | + return {'function':'add_column', 'data': [str(name)]} |
| 43 | + else: |
| 44 | + self.functions.append({'function':'add_column', 'data': [str(name)]}) |
| 45 | + except(NameError): |
| 46 | + pass |
28 | 47 |
|
29 | 48 | def all_columns(self, *args):
|
| 49 | + all_col_data = {'function':'all_columns', 'data': []} |
30 | 50 | for value in args:
|
31 |
| - self.add_column(str(value)) |
| 51 | + all_col_data['data'].append(self.add_column(str(value), all_cols = True)) |
32 | 52 |
|
33 | 53 | def finalize_cols(self):
|
34 | 54 | finalizer = '\n|'
|
|
0 commit comments