Order in metaclass
Michele Simionato
michele.simionato at gmail.com
Wed Oct 13 02:53:58 EDT 2004
Nicolas Fleury <nid_oizo at yahoo.com_remove_the_> wrote in message news:<RnWad.27059$3C6.973079 at news20.bellglobal.com>...
> In the following example:
>
> class MyMetaclass(type): pass
> class MyBaseType(object): __metaclass__ = MyMetaclass
> class MyType(MyBaseType):
> x = 4
> y = 5
> z = 6
>
> Is there any way to modify MyMetaclass to keep the order of x,y,z somewhere?
>
> Thx and regards,
> Nicolas
Short answer: No.
x, y, z are in the class dictionary. dictionaries have no order.
You could use something like
class MyType(MyBaseType):
__mylist__ = [("x", 4), ("y", 5), ("z",6)]
and use the metaclass to set the class attributes x,y and z for you.
Michele Simionato
More information about the Python-list
mailing list