dictIO.dictWriter module#

class dictIO.dictWriter.DictWriter#

Bases: object

Writer for dictionaries in dictIO dict file format, as well as JSON, XML and OpenFoam.

static write(source_dict: MutableMapping[Any, Any] | CppDict, target_file: str | PathLike[str] | None = None, mode: str = 'a', order: bool = False, formatter: Formatter | None = None)#

Write a dictionary file in dictIO dict file format, as well as JSON, XML and OpenFoam.

Writes a dictIO dict (parameter source_dict of type CppDict) to target_file. Following file formats are supported and interpreted through target_file’s file ending: no file ending -> dictIO dict file ‘.cpp’ -> dictIO dict file ‘.foam’ -> Foam dictionary file ‘.json’ -> Json dictionary file ‘.xml’ -> XML file Following modes are supported: mode = ‘a’: append to target file. If the existing file contains a dictionary, write() will append the new dict to the existing through merging. This is the default behaviour. mode = ‘w’: overwrite target file. The existing file will be overwritten.

Parameters:
  • source_dict (Union[MutableMapping[Any, Any], CppDict]) – source dict

  • target_file (Union[str, os.PathLike[str], None], optional) – target dict file name, by default None

  • mode (str, optional) – append to target file (‘a’) or overwrite target file (‘w’), by default ‘a’

  • order (bool, optional) – if True, the dict will be sorted before writing, by default False

  • formatter (Union[Formatter, None], optional) – formatter to be used, by default None

dictIO.dictWriter.create_target_file_name(source_file: str | PathLike[str], prefix: str | None = None, scope: MutableSequence[str] | None = None, format: str | None = None) Path#

Helper function to create a well defined target file name.

Parameters:
  • source_file (Union[str, os.PathLike[str]]) – source dict file

  • prefix (Union[str, None], optional) – prefix to be used, by default None

  • scope (Union[MutableSequence[str], None], optional) – scope to be reflected in the target file name, by default None

  • format (Union[str, None], optional) – format of the target dict file. Choices are ‘cpp’, ‘foam’, ‘xml’ and ‘json’, by default None

Returns:

target dict file name

Return type:

Path