473,511 Members | 12,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

module parameters

I have often wanted to pass arguments to a module.

Tyically, these are globals, such as DEBUG or VERBOSE that are set
at the top of the module -- and I want to use a different value.
For modules that provide a service (such as logging), I would like
to make my changes before the defaults are set up.

Assuming that the loaded module is cooperative, what is the least
ugly way to pass these parameters?

(1) Alter/Check __builtins__
(2) Alter/Check a "well-known" module, such as settings, for an
attribute named after the loading module.*
(3) Alter/check a modsettings module specific to module mod.
(4) Use an import hook
(5) Accept that there will be some inefficiencies and reset after
the initial load.

* I'm not aware of any such well-known module yet, but if others
agree that it sounds like a good idea, I will write one.

-jJ
Jul 18 '05 #1
2 1552
Jim Jewett wrote:


I have often wanted to pass arguments to a module.

Tyically, these are globals, such as DEBUG or VERBOSE that are set
at the top of the module -- and I want to use a different value.
For modules that provide a service (such as logging), I would like
to make my changes before the defaults are set up.

Assuming that the loaded module is cooperative, what is the least
ugly way to pass these parameters?

(1) Alter/Check __builtins__
(2) Alter/Check a "well-known" module, such as settings, for an
attribute named after the loading module.*
(3) Alter/check a modsettings module specific to module mod.
(4) Use an import hook
(5) Accept that there will be some inefficiencies and reset after
the initial load.

* I'm not aware of any such well-known module yet, but if others
agree that it sounds like a good idea, I will write one.

I'm not sure if it's a common enough need to have a standard way to do
it, if that's what you're suggesting. I suspect most programmers, if
they do use such module "arguments", will design it so that they can
be set after the module is imported. In fact, this is what I
recommend. (Then again, there is PEP 329 on the table.)

But, if you really need these arguments set before importing the
module, then I recommend #2, and the well-known module to use is
__main__. __main__ is the top level module, the one where the program
begins. Just set whatever arguments you need at the top-level, and
have the cooperating module import __main__ and use whatever it needs.
--
CARL BANKS http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work."
-- Parody of Mr. T from a Robert Smigel Cartoon
Jul 18 '05 #2
Have 2 modules a wrapper and then the foundation. The user can load the
real module which basically just lets them create an initialization
object which then sets a bunch of very oddly named globals and then
loads your desired module which looks for those.. Sort of an icky way of
doing it but it's not bad
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
18387
by: M-a-S | last post by:
I'd like to parametrize a module. That is, to set and pass some values into the module, while it is being imported. I tried this: # sub_1.py -- main program extern = "OK" import sub_2 print...
4
2169
by: Andrew E | last post by:
Hi all I've written a python program that adds orders into our order routing simulation system. It works well, and has a syntax along these lines: ./neworder --instrument NOKIA --size 23...
42
4899
by: WindAndWaves | last post by:
Dear All Can you tell me why you use a class module??? Thank you Nicolaas ---
0
1359
by: jpodesta | last post by:
Hello- I am fairly new to MS Access and would like to use some macros in .xls in an Access Module. I have tried to do this on my own but failed to make it work. I have included the xls macros...
4
2207
by: jpodesta | last post by:
I would like to add the xls macros below to the module listed. I am looking for advice as to the best way to go about this. module Public Function clean_pn(pn_in As Variant) As String
17
26507
by: Pam Ammond | last post by:
I need to use Microsoft Access Automation within a Visual Studio 2003 program written in C# for Windows Forms. When a button is clicked in my VS.NET program, I want it to run a Microsoft Access...
10
6575
by: David Bear | last post by:
Being new to pgdb, I'm finding there are lot of things I don't understand when I read the PEP and the sparse documentation on pgdb. I was hoping there would be a module that would properly escape...
2
1462
by: Joseph Turian | last post by:
Can I simulate the behavior of "from foo import *" using imp.load_module()? Here's the functionality I need: We allow the user to define parameter values, which are imported and can be...
5
2140
by: Johann C. Rocholl | last post by:
The following is my first attempt at adding a taint feature to Python to prevent os.system() from being called with untrusted input. What do you think of it? # taint.py - Emulate Perl's taint...
0
7148
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
7367
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
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
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,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.