J
James Tauber
Had a question from a colleague that I embarrassingly couldn't answer.
He has a script, foo.py with a global. He wants to import bar.py and
needs that global available in bar.py
The following obviously doesn't work:
# foo.py
my_global = "hello"
print globals().keys()
import bar
# bar.py
print globals().keys()
and results in:
['__builtins__', '__name__', '__doc__', 'my_global']
['__builtins__', '__name__', '__file__', '__doc__']
I'm not sure how to reimplement __import__ to make the global available
to the imported module.
Any suggestions?
James
He has a script, foo.py with a global. He wants to import bar.py and
needs that global available in bar.py
The following obviously doesn't work:
# foo.py
my_global = "hello"
print globals().keys()
import bar
# bar.py
print globals().keys()
and results in:
['__builtins__', '__name__', '__doc__', 'my_global']
['__builtins__', '__name__', '__file__', '__doc__']
I'm not sure how to reimplement __import__ to make the global available
to the imported module.
Any suggestions?
James