By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,144 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,144 IT Pros & Developers. It's quick & easy.

passing options to __import__

P: n/a
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 -

Apr 3 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Harold Fellermann <da******@googlemail.comwrote:
...
Within my program, I am importing a module via
__import__(module_name,globals(),locals())
The globals() you're passing are those of the *importing* module, and
have no effect on those of the *imported* module.
and I want to pass comand line options to this module. I would prefer
command-line options are sys.argv -- a list you can set in any way you
want before you __import__. Generally unwise to "fake" it, but it may
sometimes come in handy for purposes of testing (and no others).
Alex
Apr 4 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.