Enumerating Classes in Modules

Rob Snyder arkham at gmail.com
Wed Nov 17 18:00:31 EST 2004


Greetings -

I have a situation where I need to be able to have a Python function that
will take all the modules in a given directory and find all the classes
defined in these modules by name. Ultimately, I would need to loop through
all of these, instantiating each of the classes in turn and calling a
pre-known method of each.

Finding the name of each module is not a problem, but loading the classes
out the module once I know the name is where I'm lost.

The idea is basically to support "plug-ins" for an application I'm building.
I want the end user to be able to sub-class an example plug in class, then
throw the implementation in a given directory, where I'll find it
automatically when I need it.

I *am* still relatively new to Python, so I fully appreciate that I may be
simply going about this all the wrong way. Any guidance or redirection
anyone can provide would be appreciated.

Many Thanks.

Rob Snyder



More information about the Python-list mailing list