Oct-10-2018, 08:57 AM
Can use
my_module.py:
A module is always fully imported,so doing
So
But whether you use anything else from the module or not,it's always fully imported.
Then can access all other names from it.
from my_module import d
my_module.py:
a = 100 b = 200 c = 300 d = 400bar.py:
from my_module import d print(d)
Output:400
So now have access to only d
in bar.py
.A module is always fully imported,so doing
import my_module
and from my_module import d
make no difference in bottom.So
sys.modules['my_module']
has reference to whole file.>>> import sys >>> sys.modules['my_module'] <module 'my_module' from 'E:\\div_code\\new\\my_module.py'>
from my_module import d
point straight to d
.But whether you use anything else from the module or not,it's always fully imported.
import my_module
binds the name my_module
to sys.modules['my_module']
.Then can access all other names from it.
>>> import my_module >>> my_module.a 100 >>> my_module.b 200 >>> my_module.d 400