[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Strange Result about Module circular rreference

CFAN

2/3/2008 12:59:00 AM

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" ?
1 Answer

CFAN

2/3/2008 1:02:00 AM

0

On 2?3?, ??8?59?, CFAN <eyeli...@gmail.com> wrote:
> 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" ?

The result is got from Pythonwin Shell , and I'v try it from command
C:\Documents and Settings\yoyo\My Documents>python Script4.py
ModuleM3
ModuleM1
ModuleM2
it seems the it really works