473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Retrieving classes from a module...

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
3 1376
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
> >>> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Corey Lubin | last post by:
someGlobal=1 class Original: def foo(self): # Make use of someGlobal from original import * someGlobal=2
7
by: Paulo Pinto | last post by:
Hi, I have a package that generates classes from a set of XML files using exec. So far the classes appear in the global namespace. Is there any way to also create packages dinamicaly and...
12
by: David MacQuigg | last post by:
I have what looks like a bug trying to generate new style classes with a factory function. class Animal(object): pass class Mammal(Animal): pass def newAnimal(bases=(Animal,), dict={}):...
3
by: nathan_kent_bullock | last post by:
Assume I am using a class Foo. I want to find out the modification time of the file that that class was defined in. How would I go about this? If I could find out the name of the file that Foo...
0
by: François Pinard | last post by:
Hi, everybody. I wish someone could advise me. I'm running in circles, trying to find an elegant way to devise run-time pluggable classes. It all goes around method resolution order, I guess....
3
by: Oenone | last post by:
I am trying to write a generic piece of code that I can copy between projects that uses the current project's root namespace as part of its function. I can easily retrieve this value when I am...
5
by: Alex | last post by:
Hi, this is my first mail to the list so please correct me if Ive done anything wrong. What Im trying to figure out is a good way to organise my code. One class per .py file is a system I like,...
4
by: digitalorganics | last post by:
Is there a method or attribute I can use to get a list of classes defined or in-use within my python program? I tried using pyclbr and readmodule but for reason that is dogslow. Thanks in...
9
by: Stef Mientki | last post by:
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 ? thanks, Stef Mientki
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.