By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Retrieving classes from a module...

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

Thomas
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Thomas Aanensen wrote:
How can I get the names of the classes in a specific module? (I don't need
the subclasses or superclasses)

pyclbr.readmodule("csv").keys() ['Dialect', 'DictReader', 'excel', 'excel_tab', 'DictWriter', 'Sniffer']


Peter
Jul 18 '05 #2

P: n/a
> >>> 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?
Jul 18 '05 #3

P: n/a
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

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.