maci.yamldumpall

dumps multiple yaml docs to a file

dumping a file

Dumps any iterable with the corresponding python data types to a file with each item formatted as individual YAML documents. Nothing is returned. Creates a new or overwrites an existing file by default (See append parameter to change mode).

Basic Example of dumping data to a file as multiple docs using default positional parameters

maci.yamldumpall('mydata.yml', data)

In this example, we simply dump data that is an iterable object to a file using the yamldumpall function and pass a string of the filepath to the file as the first argument to the function, then pass the data as the second argument to the function.

The data passed in will be iterated over with each item being an individual yaml document in the file. Information on multiple YAML docs in a file: https://yaml.org/spec/1.2.2/ https://gettaurus.org/docs/YAMLTutorial/#YAML-Multi-Documents

parameters & arguments

Describes all parameter functionality and accepted data types

filename: str | Path

First required positional argument. Accepts strings and Path objects

Use this parameter to point to your filepath

data: Iterable[Any]

Second required positional argument. Accepts Iterable[Any]

Use this parameter to pass in the data you want to dump to a file.

append: bool

Optional parameter. Accepts booleans. Default = False

Use this parameter to enable appending mode to write by appending data to the file. A new file will be created if the filename does not exist. Default is disabled which writes new or overwrites a file.

encoding: str | None

Optional parameter. Accepts strings or None. Default = None

Use this parameter to dump the data with the desired codec of the data if needed. The default uses the default of python, so you don't have to use this, but you can if the data needs to be written with a specific codec.

This function uses the PyYAML framework installed as a dependency from pypi for its underlying functionality. It is only using the "safe_dump_all" method, which only supports standard YAML tags and cannot represent an arbitrary Python object. For more information on PyYAML, visit: https://pypi.org/project/PyYAML/

Last updated