DictParser¶
- class dictIO.dict_parser.DictParser¶
Bases:
objectParser for dictionaries in dictIO native file format, as well as JSON and XML.
DictParser is a convenience class. DictParser.parse() combines the operations of DictReader.read() and DictWriter.write() .
- __init__() None¶
Initialize a dictionary parser.
- Return type:
None
Methods
__init__()Initialize a dictionary parser.
parse(source_file, *[, includes, mode, ...])Parse a dictionary file and save it with prefix 'parsed.'.
- static parse(source_file: str | PathLike[str], *, includes: bool = True, mode: str = 'w', order: bool = False, comments: bool = True, scope: MutableSequence[TKey] | None = None, output: str | None = None) SDict[Any, Any] | None¶
Parse a dictionary file and save it with prefix ‘parsed.’.
This convenience method combines DictReader.read and DictWriter.write.
The parsed output is written with the parsed. prefix. For example, parsing xyz creates parsed.xyz. Output uses dictIO’s native format by default; JSON, XML, and OpenFOAM formats are also supported.
- Parameters:
source_file (str | PathLike[str]) – Dictionary file to parse.
includes (bool) – Whether to merge sub-dictionaries referenced by include directives. Defaults to True.
mode (str) – Whether to append (“a”) to an existing output file or overwrite it (“w”). Defaults to “w”.
order (bool) – Whether to sort the parsed dictionary. Defaults to False.
comments (bool) – Whether to write comments to the output file. Defaults to True.
scope (MutableSequence[TKey] | None) – Keys to retain after parsing. If None, do not reduce the dictionary by scope. Defaults to None.
output (str | None) – Output format (“cpp”, “foam”, “xml”, or “json”). If None, infer the format from the default behavior. Defaults to None.
- Returns:
Parsed dictionary, or None if the writer does not return a parsed dictionary.
- Raises:
FileNotFoundError – If source_file does not exist.
- Return type:
SDict[Any, Any] | None