[Tutor] oh, BTW-

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 9 Jan 2002 00:23:01 -0800 (PST)


On Wed, 9 Jan 2002, Andy W wrote:

> > (subroutines) without bothering to pass it to them- makes coding much
> > easier, but I did not read how to do this. Either someone slip me a
> > tip, or point me at the right part of themanual, ok?
> 
> Some time before referencing the variable within your function
> (preferably at the very start), write "global variablename". eg.
> 
> def function_name():
>    global variable_name
>    #...


But as a warning: be careful about doing this.  You may want to consider
passing the parameters explicitely; perhaps there's a better way to do
what you're trying to do, without using globals.

Global variables can be a nightmare during debugging, because you lose the
ability to easily look at each piece of your program in isolation.