Menu

Tree [2c59bd] default tip /
 History

Read Only access


File Date Author Commit
 .hgtags 2022-03-17 Anthon van der Neut Anthon van der Neut [2c59bd] Added tag 0.1.0 for changeset cd6e3e0bd943
 LICENSE 2022-03-17 Anthon van der Neut Anthon van der Neut [cd6e3e] initial version
 README.rst 2022-03-17 Anthon van der Neut Anthon van der Neut [cd6e3e] initial version
 _README.ryd 2022-03-17 Anthon van der Neut Anthon van der Neut [cd6e3e] initial version
 __init__.py 2022-03-17 Anthon van der Neut Anthon van der Neut [cd6e3e] initial version
 __plug_in__.py 2022-03-17 Anthon van der Neut Anthon van der Neut [cd6e3e] initial version
 setup.py 2022-03-17 Anthon van der Neut Anthon van der Neut [cd6e3e] initial version
 tox.ini 2022-03-17 Anthon van der Neut Anthon van der Neut [cd6e3e] initial version

Read Me

ruamel.yaml.bytes

version:0.1.0
updated:2022-03-17

This plug-in adds a method dump_to_bytes to the ruamel.yaml.YAML instance that returns a (UTF-8) bytes array

Installation

The module can be installed from PyPI using:

pip install ruamel.yaml.bytes

This module is dependent on ruamel.yaml, so you do not have to explicitly make your module depending on both.

Usage

import ruamel.yaml

yaml = ruamel.yaml.YAML(typ=['rt', 'bytes'])
data  = dict(abc=42, help=['on', 'its', 'way'])
print('retval', yaml.dump_to_bytes(data).decode('utf-8'))
print('>>>> done')

which gives:

retval abc: 42
help:
- on
- its
- way
>>>> done

Please note that there is no final newline added to the bytes array returned, and that the >>>> done is on the next line is caused by the print() function adding a newline by default. Alternatively the first call to print could be:

print('retval', yaml.dump_to_bytes(data, add_final_eol=True).decode('utf-8'), end='')

with the same effect.

.dump_to_bytes() can be shortened to .dumpb()

ChangeLog

NEXT:
  • initial plug-in version
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.