Python 2.6 Global Variables
benjamin.kaplan at case.edu
Thu Oct 29 02:20:06 CET 2009
On Wed, Oct 28, 2009 at 8:50 PM, mattofak <mattofak at gmail.com> wrote:
> Hi All;
> I'm new to Python and moving from C, which is probably a big source of
> my confusion. I'm struggling with something right now though and I
> hope you all can help.
> I have a global configuration that I would like all my classes and
> modules to be able to access. What is the correct way to do this?
Make a separate module with all the config stuff in it, and import
that module everywhere you need it. Just make sure you do "import
settings" and not "from settings import *". The behavior is different.
In the first case, one instance of the module is shared among every
module that imports it, so any changes you make will appear in all
modules. IN the second case, the current values in settings.py are
copied into the local namespace. Changes made in one module won't
appear in the other modules.
> Matthew Walker
More information about the Python-list