Import multiple files from a folder in Python

I have a folder in my application directory called Commands.folder. I want to import all modules in this folder, regardless of name, into the imported python file. How can i do this?

+3
source share
2 answers
from Commands import *

You must create an empty file named " __init__.py" in the "Commands" folder, and your main script application should be in the "Application" folder you specified.

Please note that “from importing a module” is not recommended, as this may cause namespace pollution.

Read this .

+3
source

, /, :

from Commands import *
+2

Source: https://habr.com/ru/post/1755434/


All Articles