-
Notifications
You must be signed in to change notification settings - Fork 8
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
How to preserve order when dumping? #28
Comments
In the end I just did this. Seems like a fundamental yaml limitation
|
There are two answers to this:
|
@childsish but dictionaries are insertion ordered as of Python 3.6. Using a list instead of dict is not a suitable workaround; please re-open. Most tools preserve dict orderings in python, and the ones that don't just cause friciton |
My previous comment was misleading. You can actually provide The default behaviour of PyYAML is to sort the keys and there's a long discussion (yaml/pyyaml#110) about whether PyYAML should preserve the order by default or sort the keys and whether preserving the order is backwards compatibility breaking. I agree that preserving the original order is the more intuitive option and after much thinking have decided to make the switch. However, I will consider this to be backwards compatibility breaking and change the major version number to reflect this. I just hope nobody relies on the keys being sorted on dumping... 😬 If you need your keys to be sorted, please use version 1.3.5 (4499770). Otherwise the brand new 2.0.0 will be for you. |
How to preserve order when dumping?
The text was updated successfully, but these errors were encountered: