-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfix_lab.py
40 lines (31 loc) · 1.07 KB
/
fix_lab.py
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
#!/usr/bin/env python
# A script for fixing typos, etc. in .lab files
# Kyle Gorman <[email protected]>
from os import path
from sys import argv
from glob import glob
def error():
print """
fix_lab.py: a script for fixing typos in .lab files
USAGE: ./fix_lab.py TYPO CORRECTION FOLDER
TYPO and CORRECTION will be treated as strings. FOLDER is a path where the
.lab files can be found. If TYPO or CORRECTION contains whitespace, delimit
them with a single (right) quote (e.g., the <'> character)
"""
exit(1)
if __name__ == '__main__':
if len(argv) != 4:
error()
# parse args
typo = argv[1]
correction = argv[2]
# make corrections
for file in glob(path.join(argv[3], '*.lab')):
words = open(file, 'r').readline().split()
typoed = False
for i in xrange(len(words)):
if words[i] == typo:
words[i] = correction
typoed = True
if typoed: # needs a correction
open(file, 'w').write(' '.join(words))