N
News123
Hi,
I wondered about the best way, that a module's function could determine
the existance and value of variables in the __main__ module.
What I came up with is:
########### main.py ##########
import mod
A = 4
if __name__ == "__main__": mod.f()
########### mod.py ##########
def f():
try:
from __main__ import A
except ImportError as e:
A = "does not exist"
print "__main__.A" ,A
Is there anything better / more pythonic?
Thanks in advance and bye
N
I wondered about the best way, that a module's function could determine
the existance and value of variables in the __main__ module.
What I came up with is:
########### main.py ##########
import mod
A = 4
if __name__ == "__main__": mod.f()
########### mod.py ##########
def f():
try:
from __main__ import A
except ImportError as e:
A = "does not exist"
print "__main__.A" ,A
Is there anything better / more pythonic?
Thanks in advance and bye
N