Created
August 29, 2016 02:19
-
-
Save BBischof/ae3ce0c95a073d7cd7dd504e8b48c71e to your computer and use it in GitHub Desktop.
A simple model of how to make a op controller in Python; convenient for data processing scripts with multiple functions.
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
''' | |
A simple example of how to use an operation controller | |
(note, this doesn't run, all the functions are missing) | |
''' | |
''' | |
operation controller | |
''' | |
def controller(op_code, data, data2): | |
ops = { | |
1: lambda: method1(data), | |
2: lambda: method2(data, json.load(open(data2, 'r')), False), | |
3: lambda: method2(data, json.load(open(data2, 'r')), True), | |
4: lambda: method3(data), | |
5: lambda: method1(dedup_assist_types(data)), | |
6: lambda: method2(dedup_assist_types(data), json.load(open(data2, 'r')), False), | |
7: lambda: method2(dedup_assist_types(data), json.load(open(data2, 'r')), True), | |
8: lambda: method3(dedup_assist_types(data)) | |
} | |
return ops.get(int(op_code))() | |
''' | |
main | |
''' | |
def main(op_code, file, data2): | |
with open(file) as f: | |
data = create_data(f) | |
print controller(op_code, data, data2) | |
''' | |
Takes three arguments, first is op_code, | |
second is a data file, third is another data file | |
''' | |
if __name__=="__main__": | |
main(sys.argv[1], sys.argv[2], sys.argv[3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment