module parameters

Jim Jewett JimJJewett at yahoo.com
Mon Apr 19 23:22:20 EDT 2004


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



More information about the Python-list mailing list