@@ -13,7 +13,7 @@ from __future__ import division
13
13
import math
14
14
import time
15
15
import sys
16
-
16
+
17
17
def progressbar(cur, total):
18
18
percent = '{:.2%}'.format(cur / total)
19
19
sys.stdout.write('\r')
45
45
# coding=utf-8
46
46
47
47
from __future__ import division
48
-
48
+
49
49
import sys,time
50
50
j = '#'
51
51
if __name__ == '__main__':
71
71
# coding=utf-8
72
72
73
73
from __future__ import division
74
-
74
+
75
75
import sys,time
76
76
if __name__ == '__main__':
77
77
for i in range(1,61):
94
94
```
95
95
# coding=utf-8
96
96
97
- class progressbarClass:
97
+ class progressbarClass:
98
98
def __init__(self, finalcount, progresschar=None):
99
99
import sys
100
100
self.finalcount=finalcount
@@ -118,7 +118,7 @@ class progressbarClass:
118
118
if not self.finalcount : return
119
119
self.f.write('\n------------------- % Progress -------------------\n')
120
120
return
121
-
121
+
122
122
def progress(self, count):
123
123
#
124
124
# Make sure I don't try to go off the end (e.g. >100%)
@@ -132,19 +132,19 @@ class progressbarClass:
132
132
if percentcomplete < 1: percentcomplete=1
133
133
else:
134
134
percentcomplete=100
135
-
135
+
136
136
#print "percentcomplete=",percentcomplete
137
137
blockcount=int(percentcomplete/2)
138
138
#print "blockcount=",blockcount
139
139
if blockcount > self.blockcount:
140
140
for i in range(self.blockcount,blockcount):
141
141
self.f.write(self.block)
142
142
self.f.flush()
143
-
143
+
144
144
if percentcomplete == 100: self.f.write("\n")
145
145
self.blockcount=blockcount
146
146
return
147
-
147
+
148
148
if __name__ == "__main__":
149
149
from time import sleep
150
150
# pb=progressbarClass(8,"*")
@@ -165,28 +165,56 @@ if __name__ == "__main__":
165
165
##################################################
166
166
```
167
167
168
+ 但是这样的最好看
169
+
170
+ ```
171
+ # -*- coding: utf-8 -*-
172
+ from __future__ import division
173
+ import sys
174
+ import time
175
+
176
+ def progress():
177
+ for i in range(100):
178
+ sys.stdout.write("\r[%s%s] %2d%%" % ('█' * i, ' ' * (99 - i), (i / 99) * 100))
179
+ sys.stdout.flush()
180
+ time.sleep(0.1)
181
+ sys.stdout.write('\n')
182
+
183
+
184
+ if __name__ == '__main__':
185
+ progress()
186
+
187
+ ```
188
+
189
+ 效果是这样
190
+
191
+ ```
192
+ # python download_progress_demo.py
193
+ [███████████████████████████████████████████████████████████████████████████████████████████████████] 100%
194
+ ```
195
+
168
196
## progressbar
169
197
170
198
```
171
199
# coding=utf-8
172
200
173
201
from __future__ import division
174
-
202
+
175
203
import sys,time
176
204
import progressbar
177
205
total = 1000
178
-
206
+
179
207
# 基本用法
180
208
progress = progressbar.ProgressBar()
181
209
for i in progress(range(total)):
182
210
time.sleep(0.01)
183
-
211
+
184
212
pbar = progressbar.ProgressBar().start()
185
213
for i in range(1,1000):
186
214
pbar.update(int((i/(total-1))*100))
187
215
time.sleep(0.01)
188
216
pbar.finish()
189
-
217
+
190
218
# 高级用法
191
219
widgets = ['Progress: ', progressbar.Percentage(), ' ', Bar(marker=progressbar.RotatingMarker('>-=')),
192
220
' ', progressbar.ETA(), ' ', progressbar.FileTransferSpeed()]
@@ -200,7 +228,7 @@ pbar = progressbar.ProgressBar(maxval=100,widgets=[progressbar.Bar('=', '[', ']'
200
228
for i in xrange(100):
201
229
time.sleep(0.01)
202
230
pbar.update(i+1)
203
-
231
+
204
232
pbar.finish()
205
233
```
206
234
0 commit comments