I'm having troubles understanding global variables in python. I am trying to keep track of when a function gets called and once it does I want it to be unavailable to the user. However for some reason its not working :\
psycStat = False
def main():
form = cgi.FieldStorage()
global gasStat
global psycStat
psycStat = True
print "pyscStat"
print psycStat
if form.has_key('form'):
page = form['form'].value
if(page == "choose"):
if(form.getvalue('Radio')):
choice = form.getvalue('Radio')
choose(choice)
else:
printChoose()
elif(page == "psyc"):
if not psycStat:
global psycStat
psycStat = True
print("PsycStat:")
print psycStat
choice= form.getvalue('Radio')
pysc(choice)
else:
print("Already did psycstat")
else:
if(form.getvalue('another')):
printChoose()
else:
printGoodbye()
else:
printChoose()
For some odd reason if i leave the "global/psycStat = True" right below main() psycStat changes to true. However if its inside the if statment psycStat is True up until main() is called again, where it gets reset to False. I'm confused. Thanks for your help