Find class attributes creation order
Marcob
marcoberi at gmail.com
Mon Jun 23 12:23:49 EDT 2008
On 23 Giu, 18:08, Cédric Lucantis <o... at no-log.org> wrote:
> Le Monday 23 June 2008 17:53:07 Marcob, vous avez écrit :
>
> > Let's see these simple classes:
>
> > class base_foo()
> > pass
>
> > class foo(base_foo):
> > a=1
> > b={}
> > c="zz"
>
> > I would like to find class foo attributes creation order.
> > Using __metaclass__ is not of help because special method __new__
> > receive attrs as a dictionary and so the order isn't preserved. Any
> > other idea?
>
> I don't really understand what you want, but __new__ may accept any kind of
> attributes, this is your choice. You can use named params or a vararg list
> (which will preserve params order).
Ok, I'll try to make myself clearer.
> But in your example you're only using class attributes, so __new__ is not
> involved and they are just created once for all in the order you write them:
> a, b, c.
Yes, this is true but if another piece of code define class foo (and
consequently a, b, c) and I would like to find how many class
attributes are defined and their order, how can I do this?
It's easy to find how many attributes there are: using __dict__ or
dir() or whatever.
But to find their order isn't so easy.
Besides that I can do whatever I want with class base_foo but I can't
touch class foo.
Ciao.
Marco.
More information about the Python-list
mailing list