-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutils_misc.py
More file actions
20 lines (20 loc) · 907 Bytes
/
utils_misc.py
File metadata and controls
20 lines (20 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import sys
def printProgress(i, total, prefix='', suffix='', decimals=1, barLength=100):
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
barLength - Optional : character length of bar (Int)
"""
formatStr = "{0:." + str(decimals) + "f}"
percents = formatStr.format(100 * (i / float(total)))
filledLength = int(round(barLength * i / float(total)))
bar = '|' * filledLength + '-' * (barLength - filledLength)
sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
if i == total:
sys.stdout.write('\n')
sys.stdout.flush()