-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.py
More file actions
28 lines (23 loc) · 806 Bytes
/
FileManager.py
File metadata and controls
28 lines (23 loc) · 806 Bytes
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
class FileManager:
def open_file(file_name):
try:
lines = []
file = open(file=file_name, mode='r', encoding='utf-8')
lines = file.readlines()
file.close()
return Response(True, lines)
except FileNotFoundError:
return Response(False, exception="FileNotFound")
def save_file(file_name, lines):
file = open(file=file_name, mode='w', encoding='utf-8')
file.writelines(lines)
file.close()
class Response:
def __init__(self, success, lines=None, exception = None):
self.success = success
self.lines = lines
self.exception = exception
def was_successful(self):
return self.success, self.exception
def get_lines(self):
return self.lines