I suppose this is a general question so sorry if not posted in the right place.
Say for instance, I have a function
As described in python documentation, when python see some import statement it does the following things:
import fooname for module
import foo as barname for module
from foo import bar as bazpython finds function (or whatever)
fooand will bind this function to name
So each module is imported only one time.
To better understand import mechanics I would suggest to create toy example.
print("import is in progress") def foo(): pass
def foo(): print("before importing module") import module module.foo() print("after importing module") if __name__ == '__main__': foo() foo()
Put above files to the same directory. When
module.py is being imported it prints
import is in progress. When you launch
main.py it will try to import
module several times but the output will be:
before importing module import is in progress after importing module before importing module after importing module
So import really happens only once. You can adjust this toy example to check cases that are interesting to you.