Python 2.6 Global Variables

Chris Rebert clp2 at
Thu Oct 29 02:12:50 CET 2009

> On Oct 28, 2009, at 20:50, 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?

On Wed, Oct 28, 2009 at 6:02 PM, Ronn Ross <ronn.ross at> wrote:
> Inside the method that you want to use  the var prefix the first instance
> with global. For example: global my_var. Then you can use the var like
> normal in the method. Good luck

Note that without a global declaration, functions can still read
global variables and modify the objects associated with them, but will
be unable to re-bind (i.e. reassign) entirely different objects to
global variables; the `global` statement just permits them to rebind
global variables to new values.


More information about the Python-list mailing list