[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Iterate through slots

Gabriel Genellina

1/21/2008 5:15:00 AM

En Tue, 15 Jan 2008 16:35:52 -0200, Jared Grubb <jared.grubb@gmail.com>
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