global variables in python

Greg Jorgensen gregj at pobox.com
Fri Nov 17 11:29:10 EST 2000


"Ralf Bierig" <c00rb at dmu.ac.uk> wrote in message
news:3A155265.93721154 at dmu.ac.uk...
> hi,
>
> When I run this script (here you see only the important part of it) I
> get an error message, which says, that i use python_insert (in the
> if-statement) before I defineing it. What I would like to do is checking
> the global variable and before eventually resetting it.
> How can say to python, that it should use the global version. And not
> redefining the same variable in the function as a local variable??

Use the global statement to tell Python that the variable is in the global
namespace:

#Global variables
python_insert = 0

def read_inputfile2():
    ...
    global python_insert
    ...
    if global_insert:
        ....

--
Greg Jorgensen
Deschooling Society
Portland, Oregon, USA
gregj at pobox.com





More information about the Python-list mailing list