How to load all modules in a folder?

后端 未结 18 1651
失恋的感觉
失恋的感觉 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:04

    Add the __all__ Variable to __init__.py containing:

    __all__ = ["bar", "spam", "eggs"]
    

    See also http://docs.python.org/tutorial/modules.html

提交回复
热议问题