On Wed, 22 Dec 2004 17:52:53 -0700, Jason Child <[EMAIL PROTECTED]> wrote:
> Ok, I guess my question (now) is:
>
> how do I change global variables within a function:
>
> ##################################
> VAR = "TEST"
>
> def m():
> VAR="no test"
> ##################################
>
> when I do this (from the interactive editor):
>
> ##################################
> >>>print VAR
> TEST
> >>>m()
> >>>
> >>>print VAR
> TEST
> >>>
> ##################################
>
> any advice?
> _______________________________________________
> Tutor maillist - [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
>
>>> VAR = "TEST"
>>> def m():
global VAR ## <- this is what you were missing . . .
basically, this means
VAR = "no test" ## that, instead of assigning to a new variable
VAR in the local
## namespace of m(), you are
assigning to the variable VAR that
## was defined on the global level
>>> print VAR
TEST
>>> m()
>>> print VAR
no test
HTH,
Orri
--
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.
_______________________________________________
Tutor maillist - [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor