Answer the question
In order to leave comments, you need to log in
How to import modules correctly?
Hello.
Tell me how to import modules correctly?
For example: There are 3 files
main.py
mod1.py
mod2.py
in mod1 and mod2 I import math modules, and in main I import mod1 and mod2
Picture for understanding
Is it correct to import like this? Or is it better to do all the imports in the main.py file
I hope you understand me. Because I don't know how to put it right)
Answer the question
In order to leave comments, you need to log in
If I understood you correctly, then yes, you did everything right :)
And how do you imagine "all imports in the main.py file"? If you just do import math
in main , then math won't be "magically" available in mod1 and mod2 . If you were going to do it import math
in main and then from main import math
in mod1 and mod2 , then, of course, you don’t need to do this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question