I was reading loading of modules from here.
There are two files in one of my directory mod_a.py
and mod_b.py
.
mod_a.py
contains the following
print 'at top of mod_a'
import mod_b
print 'mod_a: defining x'
x = 5
while mod_b.py
contains
print 'at top of mod_b'
import mod_a
print 'mod_b: defining y'
y = mod_a.x
on executing mod_a.py
file I got the following output:
at top of mod_a
at top of mod_b
at top of mod_a
mod_a: defining x
mod_b: defining y
mod_a: defining x
However, while executing mod_b.py
I got the following output:
at top of mod_b
at top of mod_a
at top of mod_b
mod_b: defining y
Traceback (most recent call last):
File "D:\Python\Workspace\Problems-2\mod_b.py", line 2, in <module>
import mod_a
File "D:\Python\Workspace\Problems-2\mod_a.py", line 2, in <module>
import mod_b
File "D:\Python\Workspace\Problems-2\mod_b.py", line 4, in <module>
y = mod_a.x
AttributeError: 'module' object has no attribute 'x'
Can anybody please explain this?