Order in metaclass

Alex Martelli aleaxit at yahoo.com
Thu Oct 14 03:42:23 EDT 2004


Nicolas Fleury <nid_oizo at yahoo.com_remove_the_> wrote:
    ...
> > from happening in Python 2.x, IMHO... and I really doubt if dicts will
> > ever be changed to accomodate ordering, even in Python 3.0. Too much
> > hassle for too little gain. A hook function seems to be more sensible.
> 
> I don't know.  I was thinking that maybe an ordereddict class would be
> useful, something like:

Yes, a mapping that keeps order can be useful (in either meaning of the
term: remembering order of item insertion [or last modification], or,
intrinsically ordering keys [directly or by value]).  There are a bit
too many variants to warrant making them built-ins, but the collections
module, in Python 2.5, could certainly accomodate several.


> myDict = {'a': 4, 'b': 5 }  # normal dict
> myDict = o{'a': 4, 'b': 5 }  # ordered dict, keeping order ['a', 'b']
> 
> The dictionary could only be use in specific cases, like configuration
> stuff or temporarily when instantiating a metaclass...  I don't know,
> maybe I'm just crazy...

Given the rarity of the need, I very much doubt it makes sense to come
up with special syntax, or implicitly use some choice out of these
special mappings (no doubt slower than regular dicts) in some cases.  In
other words, I agree with Carlos that some way to tell Python what class
to use (in lieu of default dict) for class statements -- presumably a
sys.setsomething call -- is preferable; I do agree with you that users
shouldn't need to come up with their own "ordered mappings", the
standard library should provide them.


Alex



More information about the Python-list mailing list