/
filer2.py
41 lines (31 loc) · 993 Bytes
/
filer2.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
import sys
import absRel3
import os
import ast
import sys
import color
def read(path):
color.blue("Reading "+path)
content = ""
with open(path, 'r', encoding='utf-8') as content_file:
content = content_file.read()
# print(content)
return content
def readToObj(filename):
data = None
with open(filename) as fp:
data = [ast.literal_eval(line) for line in fp if line.strip()]
result = data[0] if len(data) else None
return result
def write(path, content):
content = str(content)
print("Writing file "+path+'---------------------------------------------------+++++++++++++++++++++++++++++++++++++++++')
text_file = open(path, "w", encoding='utf-8')
text_file.write(content)
text_file.close()
print(content)
def writeEvenIfNoDir(path, content):
directory = absRel3.folder (path)
if not os.path.exists(directory):
os.makedirs(directory)
write (path, content)