I'm writing a program in python which has three modules: 1. settings.py 2. init.py 3. main.py
settings.py just has one Boolean variable, the goal is to use it as a global variable(let's call it var, initialised as False
) across modules
init.py imports the var, and sets it to True
after performing some actions in a function
main.py has to check whether var == True
. If yes, proceed with the program else ask user to give some command line instructions (say, prg start) which will then call a function in init.py, which in turn will also set var==True
The problem is that since I have made a program that takes arguments from CLI, the var
is always set to False. So the only command that CLI accepts is prg start
else it prints the error message that I have written.
I need some method to let var
stay True
for rest of the session, and session actually translates to until computer is switched off.
code for main.py
first = sys.argv[0]
arguments = sys.argv[1:]
second = arguments[0]
if settings.var == False and second != "start":
print "Error, type \'prg start\' to start"
sys.exit(0)
if second == "start":
init.start()
This is what I'm trying to accomplish:
pi@raspberrypi: ~$ prg start
pi@raspberrypi: ~$ prg set color 4
Success
what is happening right now:
pi@raspberrypi: ~$ prg start
pi@raspberrypi: ~$ prg set color 4
Error, type 'prg start' to start