Python: import every module from a folder?

后端 未结 3 746
闹比i
闹比i 2021-01-01 00:28

What would be the best (read: cleanest) way to tell Python to import all modules from some folder?

I want to allow people to put their \"mods\" (modules) in a folder

3条回答
  •  遥遥无期
    2021-01-01 00:55

    You might want to try that project: https://gitlab.com/aurelien-lourot/importdir

    With this module, you only need to write two lines to import all plugins from your directory and you don't need an extra __init__.py (or any other other extra file):

    import importdir
    importdir.do("plugins/", globals())
    

提交回复
热议问题