MxyL MxyL - 7 months ago 12
Python Question

Python: Importing an "import file"

I am importing a lot of different scripts, so at the top of my file it gets cluttered with import statements, i.e.:

from somewhere.fileA import ...
from somewhere.fileB import ...
from somewhere.fileC import ...
...


Is there a way to move all of these somewhere else and then all I have to do is import that file instead so it's just one clean import?

Answer

Of course there is; just create a file called myimports.py in the same directory where your main file is and put your imports there. Then you can simply use from myimports import * in your main script.