Skip to content

Instantly share code, notes, and snippets.

@tekton
Created August 1, 2013 18:27
Show Gist options
  • Save tekton/6133900 to your computer and use it in GitHub Desktop.
Save tekton/6133900 to your computer and use it in GitHub Desktop.
Primitive switch in Python
import random
def functionToCall(x="..."):
print "I got called with " + x + "!"
class SwitchTest:
state = {}
state_dict = {0: {"stat": "one", "function": functionToCall},
1: {"stat": "two", "function": functionToCall},
2: {"stat": "thr", "function": functionToCall},
3: {"stat": "fou", "function": functionToCall}}
def testSwitch(self):
r = random.randint(0, 3)
print "Result of random int: {0}".format(r)
self.state = self.state_dict.get(r, "None")
self.state["function"](self.state["stat"])
x = SwitchTest()
print "Case 'set' for testing"
print x.state_dict
x.testSwitch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment