-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
36 lines (31 loc) · 996 Bytes
/
utils.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
import os
joinPath = os.path.join
def makedir(file):
try:
os.makedirs(file[:file.rfind("/")+1])
except:
pass
def createTemp(file:"filename of temp file"):
if not os.path.exists(file):
makedir(file)
def isFileExists(file:"filename")-> "# Judge if source file exists and deal with the errors.":
return True if os.path.exists(file) else FileNotFoundError(file)
def tryAction(string):
try:
return eval(string)
except:
return BaseException(string)
def fload(file):
if not os.path.exists(file):
print(Warning("{} does not exists.".format(file)))
return
with open(file, encoding='gb18030') as f:
s = f.read()
return s
def fsave(source, file):
if not source: return
if not os.path.exists(file):
print(Warning("{} does not exists. create the file now...".format(file)))
makedir(file)
with open(file,'w', encoding='gb18030') as f:
f.write(source)