Python: import every module from a folder?

后端 未结 3 740
闹比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 01:05

    Create a file named

     __init__.py
    

    inside the folder and import the folder name like this:

    >>> from  import * #Try to avoid importing everything when you can
    >>> from  import module1,module2,module3 #And so on
    

提交回复
热议问题