Global & Importing issues.... Newbie
Bjorn Pettersen
bjorn at roguewave.com
Mon Jul 17 12:32:43 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