-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_writer.py
34 lines (23 loc) · 879 Bytes
/
file_writer.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
from os.path import exists
class File_Writer:
def write_to_file(self, path: str, filename: str, content) -> None:
full_path = "{}/{}".format(path, filename)
file = open(full_path, "a")
file.write(content)
file.close()
def check_if_file_exists(self, path: str, filename: str) -> bool:
full_path = "{}/{}".format(path, filename)
if exists(full_path):
return True
return False
def overwrite_file(self, path: str, filename: str, content):
full_path = "{}/{}".format(path, filename)
file = open(full_path, "w")
file.write(content)
file.close()
def read_file(self, path: str, filename: str) -> str:
full_path = "{}/{}".format(path, filename)
file = open(full_path)
data = file.read()
file.close()
return data