开发者

Import multiple files from a folder in Python

I have a folder in my Application directory called Commands.folder. What I want to do is import all the modules in that folder, regardless of the name, into the python file that imports. 开发者_JAVA百科How can I do this?


from Commands import *

You should create an empty file named "__init__.py" in the "Commands" folder, and your main app script should be in the "Application" folder you've mentioned.

Note however, the "from module import *" is not recommended since it may cause namespace pollution.

Read this.


If you start your program in Application, you can import all modules in /Commands using:

from Commands import *
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜