-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent_answer_formatter.py
More file actions
executable file
·45 lines (39 loc) · 982 Bytes
/
student_answer_formatter.py
File metadata and controls
executable file
·45 lines (39 loc) · 982 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from itertools import islice
import re
from os import remove
def fixLine(line):
r = re.compile(r"[^a-zA-Z0-9ñÑ]")
line = r.sub("", line)
line = line.upper()
return line
def main():
if (len(sys.argv) != 2):
print ('Incorrect Number of Arguments\n')
exit(1)
input_name = sys.argv[1]
splitName = re.split(r'_', input_name)
teamNum = splitName[0]
teamName = splitName[1]
formattedNameNum = teamNum + '\t' +teamName
newLine = []
with open(input_name, 'r') as fin:
firstLine = True
for line in islice(fin, 0, None):
if(firstLine):
firstLine = False
line = line.rstrip('\n'
if(line+".txt" != formattedNameNum):
print ('File Name does not match File Header!')
exit(1)
else:
line = fixLine(line)
newLine.append(line)
remove(input_name)
with open(input_name, 'w') as fout:
for elem in newLine:
fout.write('{}\n'.format(elem))
if __name__=='__main__':
main()