-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextProcessBase.py
More file actions
62 lines (48 loc) · 1.02 KB
/
TextProcessBase.py
File metadata and controls
62 lines (48 loc) · 1.02 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
#
#
#
class TextProcessBase():
'''
This is the base class for programs based on processing a text file and saving the
output to another text file.
This provides several methods originally provided by importing methods from utils_fr.py
'''
def __init__(self, fname=None):
'''
'''
self.infilename = "";
self.outfilename = "";
self.outli = [];
self.lines = [];
def set_infilename(self, name):
'''
'''
self.infilename = name
def set_outfilename(self, name):
'''
'''
self.outfilename = name
def read_input(self):
'''
'''
try:
batch_file = open(self.filename, 'r+')
bfile_lines = batch_file.readlines()
batch_file.close()
except:
print "Not a valid file"
if split_lines:
for elem in bfile_lines:
self.lines.append(elem.split(split_char))
else:
self.lines = bfile_lines
def write_output(self):
'''
'''
try:
outfile = file(self.outfilename, 'w')
outfile.write('\n'.join(self.outli))
outfile.close()
except:
print 'Writing to File ', filename, ' Failed'