myparentclass.__subclasses__() not working for me

samwyse samwyse at
Mon Sep 14 15:30:07 CEST 2009

### I've tried this under both Python 2.5.1 and 3.1.1, and it isn't
working with either one.  Here is my program:

class Plugin(object):
    """This is the base object for a plug-in."""

def load_plugins(plugin_subdir='plugins'):
    import sys, pkgutil, imp, os.path

        # Use this path if we're running as a module.
        homedir = __path__[0]
    except NameError:
        # Use this path if we're running stand-alone.
        homedir = sys.path[0]
    plugin_path = [ os.path.join(homedir, plugin_subdir) ]

    modules = {}
    for loader, name, is_pkg in pkgutil.iter_modules(plugin_path):
        file, pathname, desc = imp.find_module(name, plugin_path)
        modules[name] = imp.load_module(name, file, pathname, desc)
    for pair in modules.items():
        print('name = %r\nmodule = %r\n' % pair)

if __name__ == '__main__':
    print('subclasses = %r\n' %(Plugin.__subclasses__()))
    print('subclasses = %r\n' %(Plugin.__subclasses__()))

### And here is my plugin, in plugins/

from plugin import Plugin
class MyPlugin(Plugin):

### When I run the main program, I get this:

subclasses = []

name = 'myplugin'
module = <module 'myplugin' from 'C:\Documents and Settings\sam_denton

subclasses = []

###  Obviously, myplugin is being found found and loaded, but my base
class doesn't know about it.  Any ideas?

More information about the Python-list mailing list