[Python-3000] Ordered mapping type for Python 3000?
jcarlson at uci.edu
Wed Mar 28 17:33:08 CEST 2007
"BJörn Lindqvist" <bjourne at gmail.com> wrote:
> On 3/28/07, Josiah Carlson <jcarlson at uci.edu> wrote:
> > "BJörn Lindqvist" <bjourne at gmail.com> wrote:
> > > el = make_el('input', type = 'text', class = 'query')
> > XML elements are not ordering sensitive.
> Except when you write them. If you want the output to be exactly
> <input type = 'text' class = 'query'/> you must have an order.
I've not come across a case where web browsers or other XML consumers
have cared about those kinds of orderings (except in testing cases).
And those cases where order has mattered, sorting by name (so as to
consistantly produce <input class = 'query' type = 'text'/> as in your
example) gets one a consistant ordering in all Pythons.
> > > col = attrtuple(r = 255, g = 0, b = 128)
> > > r, g, b = col
> > That is handled reasonably well with Raymond's recipe (or variants
> > thereof).
> Well, no. NamedTuple('Color', 'r g b')(r = 255, g = 0, b = 128) is not
> at all the same thing.
> > > Or interface easier with tabular, order-dependent data.
> > That is handled with the ordered dictionary and metaclass sytax PEP.
> Yes. Making **kwargs orderable would merely be the syntactic support
> that would make ordered dictionaries a breeze to work with.
That is not what I meant. For data defined as columns, etc., where
order matters (also in the case of NamedTuple), PEP 3115 handles this
case fairly well, generally like:
r = g = b = None
a = Color(r = 255, g = 0, b = 128)
firstname = text
middle = text
lastname = text
Yes, you need to take the time to create the prototype. But if taking
the time to create one prototype earlier in the source to define
ordering isn't reasonable, then it seems to me that one is trying to be
too clever. Also, I find Color(r = 255, g = 0, b = 128) to be clearer
than ordered_mapping(r = 255, g = 0, b = 128) .
I would also point out that neither the OP (nor anyone else) has
proposed a possible implementation (or strategy for that matter).
More information about the Python-3000