Advertisement
igendel

plugin loader demo using import_module

Dec 8th, 2023
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import glob
  2. import importlib
  3.  
  4. plugins_dir = "plugins"
  5.  
  6. def main():
  7.  
  8.     plugins = [];
  9.     for full_name in glob.glob(plugins_dir + "/*.py"):
  10.         print("Importing plugin from " + full_name)
  11.         module_ref = full_name.replace("\\", ".")
  12.         module_ref = module_ref[0:module_ref.rfind(".py")]
  13.         plugins.append(importlib.import_module(module_ref))
  14.  
  15.     for pl in plugins:
  16.         print([item for item in pl.__dir__() if not item.startswith("__")])
  17.  
  18.  
  19. if __name__ == '__main__':
  20.     main()
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement