you need to declare it global.
Flag = 0 nuserySWdatabase = 0 # this would be from database but is set to 0 for testing def nuseryControlFunction(nuserySWdatabase): global Flag if ( nuserySWdatabase == 0 and Flag == 0): print ("pump on") Flag = 1 print Flag else: print ("pump off") Flag = 0 while 1: nuseryControlFunction(nuserySWdatabase) print FlagYet way way better would for your function to return the
flag
. If you don't change it inside the function, you can access flag
from global scope. nuserySWdatabase = 0 # this would be from database but is set to 0 for testing flag = False def nuseryControlFunction(nuserySWdatabase): if nuserySWdatabase == 0 and not flag: print("pump on") return True else: print("pump off") return False while True: flag = nuseryControlFunction(nuserySWdatabase) print(flag)But still better would be to if your function has
flag
as second parameter (if you need it at all - from your code I cannot decide if it really needed).nuserySWdatabase = 0 # this would be from database but is set to 0 for testing flag = False def nuseryControlFunction(nuserySWdatabase, flag): if nuserySWdatabase == 0 and not flag: print("pump on") return True else: print("pump off") return False while True: flag = nuseryControlFunction(nuserySWdatabase, flag) print(flag)Also, note your names do not comply with PEP8 recommendations but I kept them
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs