Newbie namespace question
Nick Coghlan
ncoghlan at iinet.net.au
Thu Dec 23 07:59:04 EST 2004
Brandon wrote:
> I did the constructor thing and just didn't like it, it didn't feel
> clean (I know, I know and monkeying with __builtin__ is?)
>
> As for global, that will just make it modlue-level global (I think?)
> and I have this reference in multiple modules. I think I tried it
> already, but I can't remember for sure... Anyway, all of this got me
> brainstorming and I think I've got a solution that I think is clean and
> will be effective, I'll bust it out and post it here for comments.
> Thanks for your input!
>
Another option for you to consider:
#__main__ ( I forget the script's name)
import app_config
app_config.setConfiguration(AdminConfig)
from jdbc import DataStore
. . .etc
#jdbc.py
from app_config import AdminConfig
. . .etc
#app_config.py
def setConfiguration(adm_cfg):
global AdminConfig
AdminConfig = adm_cfg
The reason the import solution was breaking for you earlier was that you were
setting up circular imports by using your main script as the holder for the
global configuration.
By creating a special 'configuration data' module, you can use that to store the
data, and every module that needs it can import it without worrying about
circular imports.
Any extra global configuration properties can be added by updating the
'setConfiguration' function.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list