passing options to __import__

Harold Fellermann dadapapa at googlemail.com
Tue Apr 3 18:31:38 EDT 2007


Dear list,

I looked through the list but could not find any solutions for my
current problem.
Within my program, I am importing a module via
__import__(module_name,globals(),locals())
and I want to pass comand line options to this module. I would prefer
not to save them
in a config module or a Config class but rather use the globals and
locals dictionaries
that are given to __import__. Unfortunately, they don't show up in the
globals or
locals in the module. Even setting them specifically by

params = globals()
params['module_opts'] = module_opts
__import__('my_module',params,locals())

does not work. When I put the debug statement

print 'module_opts' in globals()

into my_module, it prints 'False'. Unfortunately, the docs for
__import__ are a bit vague
about the precise role of the globals argument. Is there any way, to
acheive what I am
trying, or do I need to fall back on a config module/class?

Thanks!

- harold -




More information about the Python-list mailing list