-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwriteAnswer.py
More file actions
28 lines (24 loc) · 903 Bytes
/
writeAnswer.py
File metadata and controls
28 lines (24 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import argparse
import json
def readAnswer(fp, ext):
with open(fp, "r") as file:
# final = list(file)[-1]
# formatted_final = final.replace('\\n', '\n').replace('\\t', '\t')
answer_raw = list(file)[-1].split(',')
id = answer_raw[0]
control = answer_raw[1]
answer_json = ','.join(answer_raw[2:])
answer_obj = json.loads(answer_json)
with open ('./AnswerAnalysis.' + ext, 'w') as out:
num = answer_obj['num']
answer = answer_obj['answer']
out.write(answer)
def main():
# parse args
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--FileName", type=str, help="filename to read")
parser.add_argument("-e", "--Extension", type=str, help="file extension")
args = parser.parse_args()
readAnswer(args.FileName, args.Extension)
if __name__ == "__main__":
main()