C
CFAN
First Set up the following files,
m1.py
---------------------
#Module A
import m2
var1 = "ModuleM1"
m2.py
---------------------
#Module B
import m3
var1 = "ModuleM2"
m3.py
---------------------
#Module C
import m1
var1 = "ModuleM3"
main.py
----------------------
import m3
print m3.var1
print m3.m1.var1
print m3.m1.m2.var1
print m3.m1.m2.m3.var1
Then to run main.py
the result is :
ModuleM3
ModuleA
8
Traceback (most recent call last):
File "D:\WorkTools\ActivePython\Lib\site-packages\pythonwin\pywin
\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\yoyo\My Documents\Script4.py", line
5, in ?
print m3.m1.m2.m3.var1
AttributeError: 'module' object has no attribute 'm3'
,can any one explain it, this test is inspired by Python Programming
which says that the moudle can reference in
the circular manner, and I got wired about it and then try this test.
the result that 'module' object has no attribute 'm3' seems okay ,if i
assumes that import only import a module once, but how about the reult
"ModuleA " and even "8" ?
m1.py
---------------------
#Module A
import m2
var1 = "ModuleM1"
m2.py
---------------------
#Module B
import m3
var1 = "ModuleM2"
m3.py
---------------------
#Module C
import m1
var1 = "ModuleM3"
main.py
----------------------
import m3
print m3.var1
print m3.m1.var1
print m3.m1.m2.var1
print m3.m1.m2.m3.var1
Then to run main.py
the result is :
ModuleM3
ModuleA
8
Traceback (most recent call last):
File "D:\WorkTools\ActivePython\Lib\site-packages\pythonwin\pywin
\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\yoyo\My Documents\Script4.py", line
5, in ?
print m3.m1.m2.m3.var1
AttributeError: 'module' object has no attribute 'm3'
,can any one explain it, this test is inspired by Python Programming
which says that the moudle can reference in
the circular manner, and I got wired about it and then try this test.
the result that 'module' object has no attribute 'm3' seems okay ,if i
assumes that import only import a module once, but how about the reult
"ModuleA " and even "8" ?