Finding and loading subclasses dynamically. issubclass(x, base_plugin.Plugin) fails.

Osmo Maatta osmoma at gmail.com
Sun Aug 29 05:39:43 EDT 2010


Hello,

Sub class test fails.
======================
I have a program that needs to load plugin-classes during runtime.

The program has these subdirectories (modules).

$ tree
.
`-- test.py
|	
|-- plugins
|   |-- base_plugin.py
|   |-- base_plugin.pyc
|   |-- __init__.py
|   `-- oca
|       |-- __init__.py
|       |-- open_clipart.py


The plugins (sub directory) contains one or more plugin modules, in this
test-case there is only one; oca/open_clipart.py.

The plugins/base_plugin.py (contains class Plugin()) is a base class of
all plugins.

I want to list and load all plugin-classes (that inherit from
base_plugin.Plugin). I have a Python code that successfully browses the
plugins, but the the test issubclass(x, base_plugin.Plugin) fails.

Please see this Python code:
http://futuredesktop.com/tmp/test6.tar.gz

Why the issubclass(entry, cls) test fails?

if issubclass(entry, cls):
....print "Found a subclass: " + key
....subclasses.append(entry)

I can see that the class names are right, even objects of these classes
are ok.

My OS is Ubuntu 10.04.
$ python --version
Python 2.6.5

The actual, final product will be this
http://www.futuredesktop.com/clipart-applet/clipart-applet.ogv
It is a ClipArt query-engine and browser.
It can translate queries from "any" language to english ;-)

Most kindly
  Osmo Antero Maatta
  Grønland, Oslo






More information about the Python-list mailing list