473,668 Members | 2,371 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 1561
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
18398
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 sub_2.noway # prints 'no extern' :-( # EOF
4
2187
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 --price MARKET --repeats 20 etc However, I'd like to add a mode that will handle, say:
42
4944
by: WindAndWaves | last post by:
Dear All Can you tell me why you use a class module??? Thank you Nicolaas ---
0
1375
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 and the module as well as where I would like the macros to run. Any input on how to make this work would be appreciated. This would automate a former 3 step process into one process. module
4
2233
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
26535
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 Module. Here is the info on the Microsoft Access Module: Microsoft Access 2003 mdb is located at: C:\C#.NET\Esperanza The mdb is called: EspThr.mdb The Module is called: Module1 The function is: Public Function WriteHTML() As Integer The result...
10
6588
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 longer text strings to prevent sql injection -- and other things just make sure the python string object ends up being a properly type for postgresql. I've bought 3 books on postgresql and none of th code samples demonstrate this. web searchs...
2
1467
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 accessed directly as variables within Python. These are defined in "parameters.py". More specifically, let's say the user creates "dir/parameters.py" and
5
2152
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 feature in Python # Copyright (C) 2007 Johann C. Rocholl <johann@rocholl.net> # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the...
0
8381
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8658
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7401
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
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 we have to send another system
2
2026
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.