-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReader.py
37 lines (31 loc) · 1.12 KB
/
Reader.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
# Universidad Nacional de Costa Rica
# II Proyecto de Estructuras de Datos
# Analizador Semántico
# Profesor: José Calvo Suárez
# Autores Dayana Gibellato y Gianluca Gibellato
import os
class Reader(object):
def __init__(self, fileName):
self._fileName = fileName
def get_plain_text(self):
try:
file = open(self._fileName, "r", encoding="utf8")
text = f"\033[94m----------------------------------------- \nFile {self._fileName} \033[0m \n\n"
text += file.read()
text += "\033[94m \n----------------------------------------- \033[0m \n"
file.close()
except FileNotFoundError:
text = "File not found"
except UnicodeDecodeError:
text = "Unicode error"
return text
def read_from_file(self):
try:
file = open(self._fileName, "r", encoding="utf8")
textList = file.readlines()
file.close()
except FileNotFoundError:
print("\u001b[31m")
print(f"File \"{self._fileName}\" not found")
os._exit(1)
return textList