question on global variables

Erik Max Francis max at alcyone.com
Thu Oct 10 06:47:06 CEST 2002


mongo57a at comcast.net wrote:

> I want to change/use a value throughout my program - what I would
> normally
> refer to as a "global" variable.
> 
> I see that there is a "global" command - and I assume its use would be
> global var_name. This I have coded (works) but I am unable to use it
> "global
> name var_name is not defined".

You'll have to give a specific code example.

>>> G = 0
>>> def f():
...  global G
...  G = 1
... 
>>> f()
>>> G
1

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Freedom is a road seldom travelled by the multitudes
\__/ Public Enemy
    The laws list / http://www.alcyone.com/max/physics/laws/
 Laws, rules, principles, effects, paradoxes, etc. in physics.



More information about the Python-list mailing list