ruyaml
ruyaml copied to clipboard
feature: Allow dumping to a string without using streams
I want to be able to use .dump() to save the output as a string for later processing.
Right now, you need to work with streams. Where the simplest code is:
# Configure YAML formatter
yaml = YAML()
string_stream = StringIO()
yaml.dump({'products': ['item 1', 'item 2']}, string_stream)
source_code = string_stream.getvalue()
string_stream.close()
It would be really nice to be able to do:
yaml = YAML()
source_code = yaml.dump({'products': ['item 1', 'item 2']}, string_stream)
Thanks
Personally I would expect this to be named consistently with the std-lib JSON library, and instead be called dumps (and loads for the load equivalent).