saveyaml#
- saveyaml(filename=None, obj=None, folder=None, jsonify=True, sort_keys=True, die=True, keepnone=False, dumpall=False, sanitizepath=True, **kwargs)[source]#
Convenience function for saving to a YAML file.
- Parameters:
filename (str) – the file to save (if empty, return string representation of the YAML instead)
obj (anything) – the object to save
folder (str) – folder if not part of the filename
jsonify (bool) – whether to convert the object to a JSON prior to saving to YAML (typically preserves more of the object structure)
sort_keys (bool) – whether to sort the keys
die (bool) – whether or not to raise an exception if saving an empty object
indent (int) – indentation to use for saved YAML
keepnone (bool) – allow
sc.saveyaml(None)to return ‘null’ rather than raising an exceptiondumpall (bool) – if True, treat a list input as separate YAML pages
sanitizepath (bool) – whether to sanitize the path prior to saving
kwargs (dict) – passed to
yaml.dump()
- Returns:
The filename saved to
Examples:
yaml = {'foo':'bar', 'data':[1,2,3]} sc.saveyaml('my-file.yaml', yaml, sort_keys=False) # Save to file and do not sort the keys string = sc.saveyaml(obj=yaml) # Export to string