libICEpost.src.base.dataStructures.Dictionary

@author: F. Ramognino <federico.ramognino@polimi.it> Last update: 12/06/2023

Attributes

T

Classes

Dictionary

Ordered dictionary embedding some useful OpenFOAM-like methods.

Module Contents

libICEpost.src.base.dataStructures.Dictionary.T
class libICEpost.src.base.dataStructures.Dictionary.Dictionary(*args, _fileName: str = None, **argv)[source]

Bases: collections.OrderedDict, libICEpost.src.base.Utilities.Utilities

Ordered dictionary embedding some useful OpenFOAM-like methods.

path: str | None
file: str | None
classmethod fromFile(fileName: str)[source]

Read the variables stored in a python file (Runs the code in the file and retrieves the local variables)

Parameters:

fileName (str) – Path of the file

Returns:

A Dictionary object containing the variables defined in the file.

Return type:

Dictionary

lookup(entryName: str, *, varType: T | Iterable[type] = None, **kwargs) T | Any[source]

Same as __getitem__ but embeds error handling and type checking.

Parameters:
  • entryName (str) – Name of the entry to look for

  • varType (type|Iterable[type], optional) – Type of the variable to lookup for. Performes type-checking if it is given. Defaults to None.

  • **kwargs (dict[str,object]) – Additional arguments to pass to the checkType function in case of type checking.

Raises:
  • KeyError – If the entry is not found

  • TypeError – If the type is not consistent with varType

Returns:

self[entryName]

Return type:

varType|Any

pop(entryName: str)[source]
entryName: str

Name of the entry to look for

Same as dictionary.pop but custom error message

lookupOrDefault(entryName: str, default: T, fatal: bool = True, **kwargs) T[source]

Lookup of give a default value if not found

Parameters:
  • entryName (str) – Name of the entry to look for

  • default (T) – Instance to return in case the value is not found. It is also used for typeChecking

  • fatal (bool, optional) – If the type is not consistent rise a TypeError. Defaults to True.

  • **kwargs (dict[str,object]) – Additional arguments to pass to the checkType function in case of type checking.

Returns:

self[entryName] if entryName is found, else default

Return type:

T

_correctSubdicts()[source]

Convert recursively every subdictionary into Dictionary classes.

__setitem__(*args, **argv)[source]

Set self[key] to value.

update(/, dictionary=None, **kwargs)[source]

Performs like dict.update() method but recursively updates sub-dictionaries. Accepts both a dictionary and keyword arguments.

Parameters:

dictionary (dict, optional) – Dictionary to update with. Defaults to None.