I was wondering what happens if I call a module on different file, which imports the same python module that is already imported on the main call, is it imported twice? If yes, how can I prevent it? What is recommended way for this?
On the following example time
module is imported on the both files. As alternative solution, I passed time
module as an argument to the module call that is located on different file.
Example:
hello.py
from module import module
import time
time.sleep(1)
module();
module.py
import time; # Already imported in hello.py
def module(): #{
time.sleep(1)
print('hello')
#}
Alternative: I am passing time
module as argument into module()
function that is located under module.py
.
hello.py
from module import module
import time
time.sleep(1)
module(time);
module.py
def module(time): #{
time.sleep(1)
print('hello')
#}