-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
80 lines (52 loc) · 1.71 KB
/
tools.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
import os, sys
# import pickle #store and load variables
# import shelve #store and load variables
import bcolz
#############################
# PROGRESS BAR #
#############################
def progress(count, total, status=''):
# As suggested by Rom Ruben (see: http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console/27871113#comment50529068_27871113)
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
sys.stdout.flush()
#############################
# STORING DATA #
#############################
#############################
# SHELF #
#############################
# def store(obj, target):
# my_shelf = shelve.open(target,'n') # 'n' for new
# my_shelf[target] = obj
# my_shelf.close()
# def restore(source):
# my_shelf = shelve.open(source)
# data = my_shelf[source]
# my_shelf.close()
# return data
#############################
# PICKLE #
#############################
# def store(obj, target):
# file = open(target, 'wb')
# pickle.Pickler(file).dump(obj)
# # pickle.dump(obj, f)
# file.close()
# def restore(source):
# f = open(source, 'rb')
# obj = pickle.load(f)
# f.close()
# return obj
#############################
# BCOLZ #
#############################
def store(obj, target):
c = bcolz.carray(obj, rootdir=target, mode='w');
c.flush()
def restore(source):
return bcolz.open(source)[:]