-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
32 lines (25 loc) · 813 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
from stdlib_list import stdlib_list
import sys
import operator
import time
import json
import yaml
def check_stdlibs(module_name):
libs = stdlib_list(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
return (module_name in libs)
def mean(n):
return float(sum(n)) / max(len(n), 1)
def sort_dict(self, val, reverse=True):
val_sorted = sorted(val.items(), key=operator.itemgetter(1),
reverse=reverse)
return val_sorted
def save_json_to_file(data, filename):
name = (filename + "." + time.strftime("%Y%m%d-%H%M%S")
+ ".yml")
with open(name, 'w') as outfile:
json.dump(data, outfile, indent=4, sort_keys=True)
def yaml_load(filename):
with open(filename, 'r') as ifile:
loaded = yaml.load(ifile)
return loaded
return None