En Tue, 15 Jan 2008 16:35:52 -0200, Jared Grubb <[EMAIL PROTECTED]>  
escribi�:

> How can I iterate through the slots of a class, including those it  
> inherits
> from parent classes?
>
> class C(object):
>   __slots__ = ['a']
>
> class D(C):
>   __slots__ = ['b']
>

Iterate over all the class hierarchy keeping track of slot items:

def find_slots(cls):
   slots = set(getattr(cls, '__slots__', []))
   for base in cls.__bases__:
     slots.update(find_slots(base))
   return slots


-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to