How to Configure MonoTable¶
Override class vars in subclass¶
Create a subclass of MonoTable and override one or more MonoTable Class Variables
import monotable
class SeparatedMonoTable(monotable.MonoTable):
guideline_chars = '-=-'
separated_guidelines = True
headings = ['an int', 'string', 'another int', 'another string']
tbl = SeparatedMonoTable()
cells = [[123, 'import', 4567, 'this']]
print(tbl.table(headings, [], cells, title='Subclass of MonoTable.'))
Subclass of MonoTable.
------ ------ ----------- --------------
an int string another int another string
====== ====== =========== ==============
123 import 4567 this
------ ------ ----------- --------------
Assign to class var names¶
Assign to one or more MonoTable Class Variables on an instance.
This creates an instance variable that overrides the class variable with an instance variable of the same name.
import monotable
headings = ['an int', 'string', 'another int', 'another string']
tbl = monotable.MonoTable()
tbl.guideline_chars = '-=-'
tbl.separated_guidelines = True
cells = [[123, 'import', 4567, 'this']]
print(tbl.table(headings, [], cells, title='Override on an instance.'))
Override on an instance.
------ ------ ----------- --------------
an int string another int another string
====== ====== =========== ==============
123 import 4567 this
------ ------ ----------- --------------
Note
Double check the spelling of the class variable. A misspelled variable name will be silently ignored.
- These techniques work because:
- None of the instance variables assigned by __init__() depend on the value of any other class or instance variable.
- MonoTable member functions, except __init__(), do not modify any class or instance variables.