473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

passing options to __import__

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
1 1639
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Marco Herrn | last post by:
Hi, I am using the builtin __import__() to import modules. That works for simple modules like in this example: m= __import__("eggs") when there is the module "eggs.py" in the current...
4
by: Coder Coder | last post by:
Hi, Can someone help me with how to overload the __import__ function, so that I can call the old __import__ function and if it cannot find the library to be able to do something else. - Thanks.
7
by: Leo Breebaart | last post by:
I have another question where I am not so much looking for a solution but rather hoping to get some feedback on *which* solutions people here consider good Pythonic ways to approach a issue. ...
4
by: Joshua Kugler | last post by:
We've recently been doing some profiling on a project of ours. It runs quite fast on Linux but *really* bogs down on Windows 2003. We initially thought it was the simplejson libraries (we don't...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.