swarmsim.yaml#
YAML support for novel swarms
This module provides a custom YAML loader that defines some nice tags.
See also
See Our YAML module for how to use the custom YAML tags.
Functions#
- swarmsim.yaml.load(stream, *, Loader=<class 'swarmsim.yaml.include.IncludeLoader'>)[source]#
Parse the first YAML document in a stream and produce the corresponding Python object.
By default, this function uses our
IncludeLoader
class which processes!include
,!relpath
, and!np
tags.
- swarmsim.yaml.safe_load(stream, *, Loader=<class 'swarmsim.yaml.NaiveLoader'>)[source]#
Parse the first YAML document in a stream and produce the corresponding Python object.
This loads YAML similarly to how
ruamel.yaml
’s safe loader does, in that it ignores non-standard tags. It also handles recursively defined anchors/aliases.
- swarmsim.yaml.dump(data, stream=None, *, Dumper=<class 'swarmsim.yaml.CustomDumper'>, **kwds)[source]#
Serialize a Python object into a YAML stream. If stream is None, return the produced string instead.
By default, this function uses our
CustomDumper
class which provides a more human-readable representation ofpathlib.Path
and certain smallnumpy.ndarray
objects.
Examples
import swarmsim.yaml as yaml
# load a YAML file
with open('foo.yaml', 'r') as f:
data = yaml.load(f)
# dump a YAML file
with open('foo.yaml', 'w') as f:
yaml.dump(data, f)
Classes
|
|
|
Modules
Handles !include and !relpath tags |
|
Handle !np yaml tag. |
|
Provides a slightly more human-readable YAML representer for numpy arrays. |
|
Provides a custom representer for Path objects |
|