How to load all modules in a folder?

后端 未结 18 1598
失恋的感觉
失恋的感觉 2020-11-22 05:37

Could someone provide me with a good way of importing a whole directory of modules?
I have a structure like this:

/Foo
    bar.py
    spam.py
    eggs.py         


        
18条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 06:13

    I've created a module for that, which doesn't rely on __init__.py (or any other auxiliary file) and makes me type only the following two lines:

    import importdir
    importdir.do("Foo", globals())
    

    Feel free to re-use or contribute: http://gitlab.com/aurelien-lourot/importdir

提交回复
热议问题