Retrieving classes from a module...

T

Thomas Aanensen

How can I get the names of the classes in a specific module? (I don't need
the subclasses or superclasses)

Thomas
 
T

Thomas Aanensen

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?
 
P

Peter Otten

Thomas said:
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 * :)
['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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,512
Latest member
FinleyNick

Latest Threads

Top