Python 2.6 Global Variables

Benjamin Kaplan benjamin.kaplan at
Thu Oct 29 02:20:06 CET 2009

On Wed, Oct 28, 2009 at 8:50 PM, mattofak <mattofak at> 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 are
copied into the local namespace. Changes made in one module won't
appear in the other modules.

> Thanks;
> Matthew Walker
> --

More information about the Python-list mailing list