On 11.06.15 02:58, Chris Angelico wrote:
On Thu, Jun 11, 2015 at 8:10 AM, Devin Jeanpierre
<jeanpierr...@gmail.com> wrote:
The problem is that there are two different ways repr might write out
a dict equal to {'a': 1, 'b': 2}. This can make tests brittle -- e.g.
it's why doctest fails badly at examples involving dictionaries. Text
format protocol buffers output everything sorted, so that you can do
textual diffs for compatibility tests and such.

With Python's JSON module [1], you can pass sort_keys=True to
stipulate that the keys be lexically ordered, which should make the
output "canonical". Pike's Standards.JSON.encode() [2] can take a flag
value to canonicalize the output, which currently has the same effect
(sort mappings by their indices). I did a quick check for Ruby and
didn't find anything in its standard library JSON module, but knowing
Ruby, it'll be available somewhere in a gem.

AFAIK Ruby's dicts are ordered. So the output is pretty stable.


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to