module documentation

Read and write 2DA files (2-dimensional array, similar to CSV).

Class DictReader Undocumented
Class DictWriter Undocumented
Function read Reads a 2DA file and returns a DictReader object.
Function write Writes data to a file using the specified columns.
Constant CELL A type alias for a cell value, which can be a string or None (****).
Function _escape_cell Undocumented
Function _split_twoda_style Undocumented
Constant _MAGIC Undocumented
def read(file: TextIO): (source)

Reads a 2DA file and returns a DictReader object.

Example

>>> with open("file.2da", "r") as f:
...     for row in twoda.read(f):
...         print(row)
Parameters
file:TextIOThe 2DA file to read.
Returns
DictReaderAn object that allows reading the 2DA file as a dictionary.
Raises
ValueErrorParse/format errors.
def write(file: TextIO, columns: list[str]) -> DictWriter: (source)

Writes data to a file using the specified columns.

Example

>>> with open("file.2da", "w") as f:
...     writer = twoda.write(f, ["col1", "col2"])
...     writer.add_row({"col1": "foo", "col2": "bar"})
...     writer.add_row({"col1": "baz", "col2": "qux"})
Parameters
file:TextIOThe file object where the data will be written.
columns:list[str]A list of column names to be used in the output file.
Returns
DictWriterAn instance of DictWriter initialized with the given columns and file.

A type alias for a cell value, which can be a string or None (****).

Value
str | None
def _escape_cell(cell: CELL): (source)

Undocumented

def _split_twoda_style(line: str) -> list[CELL]: (source)

Undocumented

_MAGIC: str = (source)

Undocumented

Value
'2DA V2.0'