Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Allow dumping to a string without using streams #27

Open
lyz-code opened this issue Nov 24, 2020 · 1 comment
Open

feature: Allow dumping to a string without using streams #27

lyz-code opened this issue Nov 24, 2020 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@lyz-code
Copy link
Collaborator

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

@gdubicki gdubicki added the help wanted Extra attention is needed label Dec 7, 2021
@pelson
Copy link

pelson commented Aug 30, 2022

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants