passing globals to imported module

James Tauber jtauber at
Mon Aug 16 21:00:05 CEST 2004

Had a question from a colleague that I embarrassingly couldn't answer.

He has a script, with a global. He wants to import and
needs that global available in

The following obviously doesn't work:

my_global = "hello"
print globals().keys()
import bar

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 Tauber     
  journeyman of some

More information about the Python-list mailing list