-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
52 lines (42 loc) · 1.29 KB
/
util.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
40
41
42
43
44
45
46
47
48
49
50
51
52
import os, string, random
def mkIfNone(path):
if not os.path.exists(path):
if path.replace("\\","/").split("/")[-1].replace(".","")!=path.replace("\\","/").split("/")[-1]:
path="/".join(path.replace("\\","/").split("/")[:-1])
try:
os.makedirs(path)
except:
pass
def fo(a):
return "{0:.2f}".format(a).ljust(15)
def fo2(a):
return "{0:.2f}".format(a).ljust(len("{0:.2f}".format(a)))
def fo5(a):
return "{0:.1f}".format(a).ljust(len("{0:.1f}".format(a)))
def fo6(a):
return "{0:.4f}".format(a).ljust(len("{0:.4f}".format(a)))
def fo3(a):
return "{0:.6f}".format(a).ljust(15)
def fo4(a):
return "{0:.6f}".format(a).ljust(len("{0:.6f}".format(a)))
def splitQS(a): #split quotes and space
l=[]
new = True
quote = False
for A in a:
if new:
l.append("")
new = False
if A == ' ' and quote != True:
new = True
elif A == '\"':
quote = not quote
else:
l[-1] += A
return l
def joinQS(lis): #split quotes and space
return " ".join(["\""+l+"\"" if " " in l else l for l in lis])
def rand6(length=6):
chars = string.digits
rand = ''.join(random.choice(chars) for _ in range(length))
return rand