Global & Importing issues.... Newbie

Toby t.harris at robinsons.co.uk
Mon Jul 17 12:03:44 EDT 2000


I have a simple requirement for a second module to access a global variable
stored in the first (main) module.

I can reproduce my problem with the following 2 modules...

Mod1.PY >>>
import Mod2

myGlobal = None

if __name__ == "__main__":

  myGlobal = 100

  Mod2.DoPrint()
#endif
#endmodule


Mod2.PY >>>
import Mod1

def DoPrint():
  print Mod1.myGlobal
#enddef
#endmodule

When executing Mod1.PY I expect the answer 100 to be printed out, I get None

I also get the same problem if there is a function in Mod1 which prints the
value of myGlobal and is called from Mod2 - I think this is the same
problem.

:o(

Any help from Python experts ?

TIA Toby







More information about the Python-list mailing list