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

S

Stef Mientki

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
 
R

ryles

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

FYI, there was actually a related discussion about this just recently:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e24be42ecbee7cad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top