Global package variable, is it possible?

Chris Allen ca.allen at gmail.com
Fri Aug 3 13:00:15 EDT 2007


Hello fellow pythoneers.  I'm stumped on something, and I was hoping
maybe someone in here would have an elegant solution to my problem.
This is the first time I've played around with packages, so I'm
probably misunderstanding something here...

Here's what I'd like to do in my package.  I want my package to use a
configuration file, and what I'd like is for the config file to appear
magically in each module so I can just grab values from it without
having to load and parse the config file in each package module.  Not
quite understanding how the __init__.py file works, I expected it to
be as easy as just setting up the ConfigParser object and then I
figured (since a package is a module) that it would now be global to
my package and I could access it in my modules, but I was wrong...  I
don't want to have to pass it in to each module upon init, or anything
lame like that.  A main reason for this is that I'd like to be able to
reload the config file dynamically and have all my modules
automatically receive the new config.  There must be a way to do this,
but seeing how __init__.py's namespace is not available within the
package modules, I don't see a simple and elegant way to do this.
Does anybody have any suggestions?  Thanks!




More information about the Python-list mailing list