passing options to __import__

  • Thread starter Harold Fellermann
  • Start date
H

Harold Fellermann

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 -
 
A

Alex Martelli

Harold Fellermann said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top