Created
April 9, 2017 10:41
-
-
Save mitchellbusby/df7a250b1dd5387bb33dd7033d59edf2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
machine = { | |
'field_1': 5, | |
'field_2': 10 | |
} | |
def func_1(machine): | |
""" | |
Does something to the machine | |
""" | |
machine['field_1'] = 10 | |
return machine | |
def func_2(machine): | |
""" | |
Does something else to the machine | |
""" | |
machine['field_2'] = 5 | |
return machine | |
# This is your lookup table of inputs to functions | |
dict_of_funcs = { | |
'input_1': func_1, | |
'input_2': func_2 | |
} | |
# Lets pretend we have a file with the following line separated inputs | |
# input_1 | |
# input_2 | |
# (this is super rough btw...don't forget to close the file etc) | |
for line in file('input.txt').readlines(): | |
# Get the relevant function | |
func = dict_of_funcs[line] | |
# Apply the function | |
machine = func(machine) | |
print(machine) | |
# Ideally each machine should be a new instance of the object | |
# with no relation to the previous one - but Python doesn't really offer immutability like that |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment