A
A
Alexander Rublev2016-03-23 21:20:59
Python
Alexander Rublev, 2016-03-23 21:20:59

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
gmvg1n9uxwP4X2.jpg
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

1 answer(s)
V
VovanZ, 2016-03-23
@Meller008

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 mathin main , then math won't be "magically" available in mod1 and mod2 . If you were going to do it import mathin main and then from main import mathin mod1 and mod2 , then, of course, you don’t need to do this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question