DictWriter

class dictIO.dict_writer.DictWriter

Bases: object

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

__init__() None

Methods

__init__()

write(source_dict[, target_file, mode, ...])

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

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

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

Writes a dictIO dict (parameter source_dict of type SDict) to target_file. Following file formats are supported and interpreted through target_file’s file ending: no file ending -> dictIO native dict file ‘.cpp’ -> dictIO native 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 (MutableMapping[K, V]) – source dict

  • target_file (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 (Formatter | None, optional) – formatter to be used, by default None