Created
August 1, 2013 18:27
-
-
Save tekton/6133900 to your computer and use it in GitHub Desktop.
Primitive switch in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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