-
Notifications
You must be signed in to change notification settings - Fork 519
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
Support of ordered dictionary #523
Comments
Ordered dictionaries are the default throughout Python 3.7+ already, and enabling it on older Pythons is pretty easy by changing the default Closing this, since it'll fairly soon be the default on all supported versions of Python anyway, so not much reason to invent a special way to override beyond what already exists. |
I am using python 3.9, so I really do not understand you comment. What I am trying to do is have yaml write out the data in the correct order. JSON does this. If I read in a yaml file and then write it out in json its file is in the order of the yaml file. But if I write out a new yaml file the order is what it is, but no the order that the original yaml file was in. Makes it harder for the user to modify the yaml file. |
@DonaldWL Oh, you're probably running into the default |
hmm does this supposed to work at all? I get |
YAML does not support
from collections import OrderedDict
This is nice because you can force the order of the data within the YAML file to make it easer for the user to read.
Program:
from collections import OrderedDict
import yaml
MyYaml = OrderedDict()
MyYaml['c'] = 130
MyYaml['a'] = 10
MyYaml['b'] = 20
with open('x.yaml', 'w') as Fh:
yaml.dump(MyYaml, Fh)
Yaml File:
!!python/object/apply:collections.OrderedDict
The text was updated successfully, but these errors were encountered: