import and shared global variables

Michael Brenner brenner at informatik.uni-freiburg.de
Fri Mar 10 10:14:10 EST 2006


Ah, thanks everybody! I had thought that, although the name was set to 
"__main__", the module that was stored in sys.modules was m1 
nevertheless, not a copy.
Well, having to write "import m1" inside m1.py seems a bit peculiar - 
it's probably nicer to keep the "__main__" module free from stuff that 
has to be imported by others.  Would a module global.py (defining glob 
and imported by whoever needs it) be more pythonic? (I didn't want to do 
that because I really want to resist the temptation of introducing 
glob1, glob2, glob3...)

	michael



> To make that happen, use something like this:
> 
> glob = [1]
> def main():
>    pass
> 
> if __name__ == "__main__":
>     import m1
>     m1.main()
> 
> 
> Diez




More information about the Python-list mailing list