iode.Table.insert

Table.insert(index: int, value: str | List[str] | Tuple[str] | TableLine | TableLineType)[source]

Insert a new line in the table.

Parameters:
index: int

index where to insert a line.

value: str or list(str) or tuple(str) or TableLine or TableLineType

value of the new line. If TableLineType, ‘value’ represents the type of the new line: FILES, MODE, DATE or SEP. If str, ‘value’ represents either a separator line if it only contains characters ‘-’ or a title line. If an iterable of str, ‘value’ represents the content of the cells of the new line.

Examples

>>> from iode import SAMPLE_DATA_DIR, TableLineType
>>> from iode import Table, comments, lists, variables
>>> comments.load(f"{SAMPLE_DATA_DIR}/fun.cmt")
Loading .../fun.cmt
317 objects loaded
>>> lists.load(f"{SAMPLE_DATA_DIR}/fun.lst")
Loading .../fun.lst
17 objects loaded
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading .../fun.var
394 objects loaded
>>> table_title = "Table example"
>>> lines_titles = ["GOSG:", "YSSG+COTRES:", "OCUG:"]
>>> lines_lecs = ["GOSG", "YSSG+COTRES", "OCUG"]
>>> table = Table(2, table_title, lines_lecs, lines_titles, True, True, True)
>>> table
DIVIS | 1              |
TITLE |       "Table example"
----- | ----------------------------
CELL  |                |     "#S"
----- | ----------------------------
CELL  | "GOSG:"        |        GOSG
CELL  | "YSSG+COTRES:" | YSSG+COTRES
CELL  | "OCUG:"        |        OCUG
----- | ----------------------------
MODE  |
FILES |
DATE  |

nb lines: 11
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'
>>> index = table.index("YSSG+COTRES:")
>>> index
5
>>> # insert new separator line
>>> index += 1
>>> table.insert(index, '-')
>>> # insert new title
>>> index += 1
>>> table.insert(index, "New Title")
>>> # insert new separator line 
>>> index += 1
>>> table.insert(index, TableLineType.SEP)
>>> # insert new line with cells
>>> # "    -> STRING cell
>>> # no " -> LEC cell
>>> index += 1
>>> table.insert(index, ['"RIDG:', 'RIDG'])
>>> table
DIVIS | 1              |
TITLE |       "Table example"
----- | ----------------------------
CELL  |                |     "#S"
----- | ----------------------------
CELL  | "GOSG:"        |        GOSG
CELL  | "YSSG+COTRES:" | YSSG+COTRES
----- | ----------------------------
TITLE |         "New Title"
----- | ----------------------------
CELL  | "RIDG:"        |        RIDG
CELL  | "OCUG:"        |        OCUG
----- | ----------------------------
MODE  |
FILES |
DATE  |

nb lines: 15
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'