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]
fileName: str

Path of the file

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

NOTE: local variable ‘this’ for this file. You can access the local folder as ‘this.path’ within the dictionary.

lookup(entryName: str, *, varType: T | Iterable[type] = None) 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.

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) 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.

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.