Retrieving classes from a module...

Peter Otten __peter__ at
Tue Feb 17 12:19:47 CET 2004

Thomas Aanensen wrote:

>> >>> pyclbr.readmodule("csv").keys()
>> ['Dialect', 'DictReader', 'excel', 'excel_tab', 'DictWriter', 'Sniffer']
> Tanks. But I already knew about that one.
> The problem is that it returns all the calsses from the imported modules
> aswell. I ONLY want the names of the classes declared in the specific
> module..
> Any ideas?

Don't pollute your namespace with from module import * :-)

>>> pyclbr.readmodule("testpyclbr").keys()
['Dialect', 'Dummy', 'DictReader', 'excel', 'excel_tab', 'DictWriter',

Now filter out the extra classes:

>>> [ for c in pyclbr.readmodule("testpyclbr").values() if
os.path.basename(c.file) == ""]


More information about the Python-list mailing list