Dynamic importing of modules followed by instantiation of objects with a certain baseclass from said modules

前端 未结 4 1868
温柔的废话
温柔的废话 2021-01-04 20:31

I\'m writing an application. No fancy GUI:s or anything, just a plain old console application. This application, lets call it App, needs to be able to load plugins on startu

4条回答
  •  一生所求
    2021-01-04 20:36

    You would make this a lot easier if you forced some constraints on the plugin writer, for example that all plugins must be packages that contain a load_plugin( app, config) function that returns a Plugin instance. Then all you have to do is try to import these packages and run the function.

提交回复
热议问题