iode.Table.__setitem__
- Table.__setitem__(index: int, value: str | List[str] | Tuple[str] | TableLine)[source]
Update a line of the table.
- Parameters:
- index: int
index of the line to be updated.
- value: str or list(str) or tuple(str) or TableLine
New content for the line.
Warning
Line of type ‘MODE’, ‘FILES’, ‘DATE’ and ‘SEP’ cannot be updated.
When updating a cell content, the cell is converted to a cell of type ‘STRING’ if the new text contains double quotes, otherwise the cell becomes of type ‘LEC’.
Examples
>>> from iode import SAMPLE_DATA_DIR >>> 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'
>>> # warning: line of type 'MODE', 'FILES', 'DATE' and 'SEP' cannot be updated.
>>> # update a title line >>> table[0] = "New title" >>> table[0] New title
>>> # update cell contents >>> # warning: the cell is converted to a cell of type 'STRING' if the new text contains >>> # double quotes, otherwise the cell becomes of type 'LEC'. >>> table[5] = ('"YSSG:"', 'YSSG') >>> table[5] ('"YSSG:"', 'YSSG')
>>> table DIVIS | 1 | TITLE | "New title" ----- | -------------- CELL | | "#S" ----- | -------------- CELL | "GOSG:" | GOSG CELL | "YSSG:" | YSSG CELL | "OCUG:" | OCUG ----- | -------------- MODE | FILES | DATE | nb lines: 11 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT'