code in a module is executed twice (cyclic import problems) ?

Stef Mientki stef.mientki at gmail.com
Sat Oct 10 19:36:46 EDT 2009


hello,

I always thought code in a module was only executed once,
but doesn't seem to be true.

I'm using Python 2.5.

And this is the example:

== A.py ==
My_List = []

== B.py ==
from A import *
My_List.append ( 3 )
print 'B', My_List
import C

== C.py ==
from A import *
from B import *
print 'C', My_List

Now when you start with B.py as the main program,
this is the resulting output:

B [3]
B [3, 3]
C [3, 3]

Why is the B.py executed twice ?

thanks,
Stef



More information about the Python-list mailing list