module documentation
Read and write 2DA files (2-dimensional array, similar to CSV).
Class |
|
Undocumented |
Class |
|
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 |
Undocumented |
Function | _split |
Undocumented |
Constant | _MAGIC |
Undocumented |
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:TextIO | The 2DA file to read. |
Returns | |
DictReader | An object that allows reading the 2DA file as a dictionary. |
Raises | |
ValueError | Parse/format errors. |
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:TextIO | The file object where the data will be written. |
columns:list[ | A list of column names to be used in the output file. |
Returns | |
DictWriter | An instance of DictWriter initialized with the given columns and file. |