Gabriel Genellina wrote: > En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu > <[EMAIL PROTECTED]> escribió: > >> On Jul 17, 1:44 am, Stef Mientki <[EMAIL PROTECTED]> >> wrote: >>> I want to have a (dynamically) list of all classes defined in a py-file. >>> Is there a way of getting this list, without manually parsing the file ? >> >> I have written something that does something like this, but I am not >> sure it is the pythonic way. >> Bascially I am loading the module and then using dir() on the module >> object I am looking for >> attribute of the type classobj (for old style classes) and type type >> (for new style classes). > > There is also the pyclbr standard module > <http://docs.python.org/lib/module-pyclbr.html> that does not load the > module (just reparses enough of it to get the info needed). So a broken > import, or any other initialization error, won't hurt.
thanks Gabriel, Alex and Ben. This is indeed a good working solution, because pyclbr also specifies in which module the class is definied. In the other suggestions, you also get the class definitions of imported modules. cheers, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list