<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I’ve checked this solution. It doesn’t work as well in Python 2.7 - dumped yaml includes this ugly parts "!!python/object/apply:collections.OrderedDict».<div class="">Yes, it could be fixed by including another hundred lines of code, but it still smells like we just copy and paste existing solution.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">15 февр. 2019 г., в 8:28, Renat Akhmerov <<a href="mailto:renat.akhmerov@gmail.com" class="">renat.akhmerov@gmail.com</a>> написал(а):</div><br class="Apple-interchange-newline"><div class="">

<title class=""></title>

<div class="">
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">This looks like a solution, yes. Thanks.
<div class=""><br class=""></div>
<div class="">@Oleg, please take a look. Maybe we really decided to add a new yaml lib too early.</div>
<div class=""><br class=""></div>
<div class=""><br class=""></div>
</div>
<div name="messageSignatureSection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class=""><br class="">
<div class="matchFont">Renat</div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">On 15 Feb 2019, 00:16 +0700, Ben Nemec <<a href="mailto:openstack@nemebean.com" class="">openstack@nemebean.com</a>>, wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;" class=""><br class="">
<br class="">
On 2/14/19 10:46 AM, Oleg Ovcharuk wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;" class="">Matthew, we use not only load, but also dump. We can't use custom<br class="">
constructor and default representer - the output will be terrible.<br class="">
This custom constructor contains about 50 lines of code, representer<br class="">
would have a similar count. Also, we should think about compatibility<br class="">
with Python 2.7, 3.x and about it's performance.<br class="">
Summary, we would have about 150 lines of code, which is just copy-paste<br class="">
from `yamlloader` library.<br class="">
IMHO, it is better to use existing solutions.<br class=""></blockquote>
<br class="">
You don't need a complex representer to dump OrderedDicts. It can be<br class="">
done in about three lines:<br class="">
<a href="https://github.com/cybertron/tripleo-scripts/blob/105381d4f080394e68a40327c398d32eb9f4f580/net_processing.py#L302" class="">https://github.com/cybertron/tripleo-scripts/blob/105381d4f080394e68a40327c398d32eb9f4f580/net_processing.py#L302</a><br class="">
<br class="">
That's the code I used when I wanted to dump dicts in a particular<br class="">
order. Once you add the representer OrderedDicts are handled as you<br class="">
would expect.<br class="">
<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;" class=""><br class="">
чт, 14 февр. 2019 г. в 19:14, Matthew Thode <<a href="mailto:mthode@mthode.org" class="">mthode@mthode.org</a><br class="">
<<a href="mailto:mthode@mthode.org" class="">mailto:mthode@mthode.org</a>>>:<br class="">
<br class="">
On 19-02-14 16:58:49, Oleg Ovcharuk wrote:<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #3498db;" class="">Hi! Can you please add yamlloader library to global requirements?<br class="">
<a href="https://pypi.org/project/yamlloader/" class="">https://pypi.org/project/yamlloader/</a><br class="">
<br class="">
It provides ability to preserve key order in dicts, it supports<br class=""></blockquote>
either<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #3498db;" class="">python 2.7 and python 3.x, it provides better performance than<br class=""></blockquote>
built-in<br class="">
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #3498db;" class="">functions.<br class="">
Thank you.<br class=""></blockquote>
<br class="">
I'd like to know a little more about why we need this, yaml as a spec<br class="">
itself doesn't guarantee order so order should be stored somewhere else.<br class="">
<br class="">
If all you need is ordereddict support something like this may be better<br class="">
then adding yet another lib.<br class="">
<br class="">
<a href="https://gist.github.com/enaeseth/844388" class="">https://gist.github.com/enaeseth/844388</a><br class="">
<br class="">
--<br class="">
Matthew Thode<br class="">
<br class=""></blockquote>
<br class=""></blockquote>
</div>
</div>

</div></blockquote></div><br class=""></div></body></html>