global variables in python

Ralf Bierig c00rb at dmu.ac.uk
Fri Nov 17 10:44:37 EST 2000


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??


#Global variables
python_insert = 0


def read_inputfile2():
    """ read_inputfile(): """
    """ Read all lines after the /* PYTHON INSERT OFF */ comment """
    input_file.seek(0)
    python_insert = 1
    for line in input_file.readlines():
        if line == "/* PYTHON INSERT OFF */\n":
            python_insert = 0
        if python_insert == 0:
            output_file.write(line)


Thanks.

Ralf Bierig



More information about the Python-list mailing list