Can module access global from __main__?
Neal Becker
ndbecker2 at gmail.com
Tue Oct 11 10:41:25 EDT 2005
Everything you said is absolutely correct. I was being lazy. I had a main
program in module, and wanted to reorganize it, putting most of it into a
new module. Being python, it actually only took a small effort to fix this
properly, so that in B.py, what were global variables are now passed as
arguments to class constructors and functions.
Still curious about the answer. If I know that I am imported from __main__,
then I can do access X as sys.modules[__main__].X. In general, I don't
know how to determine who is importing me.
More information about the Python-list
mailing list