Retrieving classes from a module...

Peter Otten __peter__ at web.de
Tue Feb 17 06:19:47 EST 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',
'Sniffer']

Now filter out the extra classes:

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

Peter




More information about the Python-list mailing list