Global & Importing issues.... Newbie

bjorn at roguewave.com.bbs bjorn at roguewave.com.bbs
Mon Jul 17 12:20:02 EDT 2000


Try

  import __main__

in mod2. Or even better implement the common data in a separate module,
perhaps even as a class?

-- bjorn

Toby wrote:
>
> 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
>
> --
> http://www.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list