forked from wxylssy/LSSY
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogressBar.py
More file actions
33 lines (27 loc) · 1.09 KB
/
progressBar.py
File metadata and controls
33 lines (27 loc) · 1.09 KB
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
import sys
import datetime
class progressbar:
def start(self, title, total):
self.total = float(total)
self.start_time = datetime.datetime.now()
self.bar_len = 30
self.cur_count = 0
self.title = title
def progress(self):
self.cur_count += 1
b = self.cur_count / self.total
filled_len = int(self.bar_len * b)
more_len = self.bar_len - filled_len
percents = round(100.0 * b, 1)
bar = '>' * filled_len + '.' * more_len
# 已用时间
lost_time = datetime.datetime.now() - self.start_time
# 剩余时间
more_time = datetime.timedelta(seconds=lost_time.total_seconds() / self.cur_count * (self.total - self.cur_count))
sys.stdout.write('[%s] %s%s %s 剩余时间:%s\r' % (bar, percents, '%', self.title, more_time))
sys.stdout.flush()
if self.cur_count == self.total:
sys.stdout.write('[%s] %s%s %s 用时:%s\n' % (bar, percents, '%', self.title, lost_time))
def out_text(self, *args):
sys.stdout.write('\n')
print(*args)