On Jan 7, 2:06 am, Ian Kelly <[email protected]> wrote:
> <[email protected]> wrote:
> > Nonetheless, I'm still wondering if I could somehow replace the dict with an
> > OrderedDict.
>
> In Python 3, yes. This is pretty much the entire use case for the new
> __prepare__ method of metaclasses. See the "OrderedClass" example[...]
This isn't accurate. The OrderedClass example uses an OrderedDict to
remember the method creation order:
def __new__(cls, name, bases, classdict):
result = type.__new__(cls, name, bases, dict(classdict))
result.members = tuple(classdict)
return result
The instantiated objects __dict__ will still be a regularly
dictionary, while the assignment order is stored in the class
attribute .members.
--
http://mail.python.org/mailman/listinfo/python-list