-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.py
39 lines (31 loc) · 1017 Bytes
/
Parser.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
from Segment import *
class Parser:
""" Parses and creates segment from direction sequences"""
def __init__(self):
pass
def toSegments(self, sequence):
position = (MIDDLE, MIDDLE)
seqList = []
for segment in sequence:
temp = Segment(position[0], position[1], int(segment))
position = temp.getEndPoint()
seqList.append(temp)
return seqList
def toSequence(self, segments):
sequence = ""
for seg in segments:
sequence += str(seg.getDct())
return sequence
def readFromInput(self):
sequence = raw_input()
return self.toSegments(sequence)
def readFromFile(self, filename):
file = open(filename)
fileData = file.read()
file.close()
return self.toSegments(fileData)
def writeToFile(self, segments, filename):
seq = self.toSequence(segments)
file = open(filename, "w")
file.write(seq)
file.close()