python - List of booleans and switching it values upon interaction -


here thing! got list 3 boolean variables , want switch between them press of button. each boolean variable represents function executed if statement. how change previous value , current value in smooth way? better way using dictionary instead of list.

what tried:

gesture, mouse, keyboard = false, false, false   actionlist  = [gesture, mouse, keyboard]  if actionlist[0]:    # blah elif actionlist[1]:    # blah elif actionlist[2]:    # blah  

edit:

i managed put working code responses have received until now. still think there should better way of achieving this.

 actions = {"gesture": false, "mouse": false, "keyboard": false}   currentlen = len(actions) # 3   currentact = 1   truevalue = 0   while true:       actionname = actions.keys()[truevalue]       actionvalue = actions.values()[truevalue]       if actions.values()[(truevalue - 1 )]: # disable last         disable = actions.keys()[(truevalue - 1 )]         print "disable %s" % (disable)         actions[disable] = not actions[disable]       if currentact == currentlen:         currentact = 1         truevalue = 0         elif currentact < currentlen:         currentact = currentact + 1         truevalue = currentact - 1       if not actionvalue: # enable current         print "enable %s" % (actionname)         actions[actionname] = not actions[actionname]  

i'm not quite sure mean, might help:

actions = {"gesture": false, "mouse": false, "keyboard": false}  if actions["gesture"]:     ...  if actions["mouse"]:     ...  if actions["keyboard"]:     ... 

this uses dictionary instead of list store actions.

to change values can this:

actions["mouse"] = true 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -