I am working on a plugin system where plugin modules are loaded like this:
def load_plugins():
plugins=glob.glob(\"plugins/*.py\")
instances=[]
for
If the plugins directory does not have an __init__.py
, it isn't a package, so when you create plugins.whatever
, Python warns you that such a thing shouldn't really exist. (It couldn't be created by "import plugins.whatever
" no matter what your path is.)
Also,
/
, which is unportable. Use os.path.split
..split(".py")
to get the name without the extension, which is buggy. Use os.path.splitext
.getattr
with a string literal. getattr(plugin, "__init__")
is spelled plugin.__init__
.__init__
function. This doesn't seem right. Perhaps you want a "set_logger" function or better, to instantiate a class that takes a logger.L = L + some_other_list
to extend a list, use the extend
method, which has better performance and is more idiomatic.except Exception
. If you cannot plan to do something sane in response to an exception, your program cannot go on sanely.