Access to static members from inside a method decorator?

Bruno Desthuilliers onurb at xiludom.gro
Thu Oct 5 13:33:52 EDT 2006


Maric Michaud wrote:
> Le jeudi 05 octobre 2006 17:18, glen.coates.bigworld at gmail.com a écrit :
>> I guess my solution is slightly less elegant because
>> it requires this ugly explicit init call outside the classes that it
>> actually deals with, however it is more efficient because the dir()
>> pass happens once on module load, instead of every time I want the list
>> of exposed methods.
> 
> You can always replace the need of the init method on classes using a 
> metaclass.
> 
> This demonstrates it with Bruno's expose decorator, but it can be done with 
> your actual init func too.
> 
> In [6]: class m(type) :
>    ...:     def __init__(self, *a,**kw) :
>    ...:         for name, meth in self.__dict__.items() :

NB : This will only get methods exposeds in this class - not the one
exposeds in the parent classes...

>    ...:             if getattr(meth, '_exposed', False) :
>    ...:                 print 'exposed :', name
>    ...:
>    ...:
> 

(snip)


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list