DictReader¶
- class dictIO.dict_reader.DictReader¶
Bases:
objectReader for dictionaries in dictIO native file format, as well as JSON and XML.
- __init__() None¶
Create a reader for dictionary files.
- Return type:
None
Methods
__init__()Create a reader for dictionary files.
read(source_file, *[, includes, order, ...])Read and parse a dictionary file.
- static read(source_file: str | PathLike[str], *, includes: bool = True, order: bool = False, comments: bool = True, scope: MutableSequence[TKey] | None = None, parser: Parser | None = None) SDict[Any, Any]¶
Read and parse a dictionary file.
The file format is selected from the file extension: no file ending -> dictIO native dict file ‘.cpp’ -> dictIO native dict file ‘.foam’ -> Foam dictionary file ‘.json’ -> Json dictionary file ‘.xml’ -> XML file
- Parameters:
source_file (str | PathLike[str]) – Dictionary file to read.
includes (bool) – Whether to merge included dictionaries. If False, include directives are removed without merging. Defaults to True.
order (bool) – Whether to sort the parsed dictionary. Defaults to False.
comments (bool) – Whether to preserve comments from the source file. Defaults to True.
scope (MutableSequence[TKey] | None) – Keys that select the nested dictionary to return. If None or empty, return the full dictionary. Defaults to None.
parser (Parser | None) – Parser to use. If None, select one based on the source file format. Defaults to None.
- Returns:
The parsed file content.
- Raises:
FileNotFoundError – If source_file does not exist.
SystemExit – If scope is provided but does not exist in the file.
- Return type:
SDict[Any, Any]