[Tutor] listing classes

Thomas Pani thomas.pani at gmail.com
Tue May 20 18:47:28 CEST 2008


Hi,

dir(A) will essentially give you what you want (and a little more)

If you're only interested in classes, you can do something like:

import types
[ name for name in dir(A) if type(eval('A.'+name)) == types.ClassType ]

Thomas

Laureano Arcanio wrote:
> Hi All,
> 
> I need to have a listing of all classes defined inside a class body,
> something like this:
> 
> class A(object):
>     class B(object):
>         pass
>     class C(object):
>         pass(object):
> 
> and i need to get the classes to instantiate them.. something like this.
> 
> classes =[A,B]
> 
> Any ideas ? do i need meta classes or something ?
> 
> Thanks in advice.
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list