473,594 Members | 2,675 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 1558
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
18392
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
2179
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
4927
by: WindAndWaves | last post by:
Dear All Can you tell me why you use a class module??? Thank you Nicolaas ---
0
1367
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
2224
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
26526
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
6584
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
2146
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
7874
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
8246
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...
1
8000
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6652
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...
0
5404
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
3854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2383
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
1
1476
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1205
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.