-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileHandle.py
39 lines (32 loc) · 1.24 KB
/
FileHandle.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
class FileHandle:
def readFileWords(self, filename):
_labirinth = []
with open(filename, 'r') as f:
_lineFromFile = f.readlines()
for line in _lineFromFile:
_line = []
for loneWords in line:
_line.append(loneWords.rstrip('\n'))
_labirinth.append(_line)
#Popping the empty character at the last position of the array.
for _elem in _labirinth:
_elem.pop()
return _labirinth
def fileWriting(self, file, strList):
file = open(file,'w')
for i in strList:
for _char in i:
file.write(_char)
file.write('\n')
file.close()
def readAndWriteExample(self,labirinth, solvedLabirinth):
#Open a supost to be empty file
myfile2 = self.readFileWords(labirinth)
#Performe the GA on the myfile2 matrix
#Saving the file after the GA manipulation
self.fileWriting(solvedLabirinth,myfile2)
#Opening and showing the solved Labirinth
myfile3 = self.readFileWords(solvedLabirinth)
for element in myfile3:
print(element.__len__())
print(element)