When the software is getting bigger and bigger it could be hard to have a clean import list for each ".py" file. So the question would spring to mind is, is there any best practice for that. To shed more lights on this issue, assume that we have 5 files which they use sklearn, numpy and so forth. Now, is it ok to create a file so-called "stdafx.py", akin to what we do in C++, and instead of importing each of these packages at the top lines of the 5 files code, using
from stdafx import *
in which stdafx.py
is a batch of all these packages. In other words, it would contain:
-----------------------------stdafx.py------------------------------------
import numpy as np
import pandas as pd
from tensorflow import keras
from X import Y
.
.
.
Using something like
from stdafx import *
is almost always not the best idea, since modules tend to be recurrently imported and one should always be aware of what is being imported, as there might be conflicts between the things that are imported, especially if there's multiple such imports.The "current" namespace in which one would do the imports should not contain things that are not used, especially something for which its contents are not specified completely(
*
). This makes the code easier to read and understand the logic behind the imports and how their organized within the project.