Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
After enhancing namedtuple and ConfigParser, I found a simpler approach
that doesn't involve extending the API. The simple way is to use
ordered dictionaries directly.
With a small tweak to OD's repr, it is fully
Bob Ippolito b...@redivi.com added the comment:
Unfortunately this is a patch for the old json lib... the new one has a C
API and an entirely different method of parsing documents (for performance
reasons).
___
Python tracker rep...@bugs.python.org
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
When do you expect the new C version to go in? I'm looking forward to it.
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5381
___
Bob Ippolito b...@redivi.com added the comment:
Whenever someone applies the patch for http://bugs.python.org/issue4136 --
I don't know when that will happen.
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5381
New submission from Raymond Hettinger rhettin...@users.sourceforge.net:
If PEP372 goes through, Python is going to gain an ordered dict soon.
The json module's encoder works well with it:
items = [('one', 1), ('two', 2), ('three',3), ('four',4), ('five',5)]
json.dumps(OrderedDict(items))
Bob Ippolito b...@redivi.com added the comment:
Why? According to RFC (emphasis mine):
An object is an *unordered* collection of zero or more name/value
pairs, where a name is a string and a value is a string, number,
boolean, null, object, or array.
--
resolution: - invalid
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
Same reason as for config files and yaml files. Sometimes those files
represent human edited input and if a machine re-edits, filters, or
copies, it is nice to keep the original order (though it may make no
semantic
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
FWIW, here's the intended code for the filter in the last post:
books = json.loads(infile, object_hook=OrderedDict)
for book in books:
del book['isbn']
json.dumps(books, outfile)
Bob Ippolito b...@redivi.com added the comment:
Fair enough, but the patch isn't usable because the decoder was rewritten
in a later version of simplejson. There's another issue with patch to
backport those back into Python http://bugs.python.org/issue4136 or you
could just use the simplejson
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
Thanks. I'll write-up a patch against
http://code.google.com/p/simplejson/ and assign it back to you for review.
--
assignee: bob.ippolito - rhettinger
___
Python tracker
Armin Ronacher armin.ronac...@active-4.com added the comment:
Motivation:
Yes. JSON says it's unordered. However Hashes in Ruby are ordered
since 1.9 and they were since the very beginning in JavaScript and PHP.
--
nosy: +aronacher
___
Python
11 matches
Mail list logo