import time
import sys
toolbar_width = 40
# setup toolbar
sys.stdout.write("[%s]" % (" " * toolbar_width))
sys.stdout.flush()
sys.stdout.write("\b" * (toolbar_width+1)) # return to start of line, after '['
for i in xrange(toolbar_width):
time.sleep(0.1) # do real work here
# update the bar
sys.stdout.write("-")
sys.stdout.flush()
sys.stdout.write("]\n") # this ends the progress bar
使用tqdm可以在一秒钟内将进度表添加到循环中:
此外,还有一个图形版的tqdm,因为^{} (^{} ):
但是要小心,因为
tqdm_gui
可以引发一个TqdmExperimentalWarning: GUI is experimental/alpha
,您可以通过使用warnings.simplefilter("ignore")
忽略它,但它将忽略之后代码中的所有警告。有一些特定的库(like this one here),但也许一些非常简单的方法可以做到:
注:progressbar2是progressbar的叉子,多年来没有保养过。
相关问题 更多 >
编程相关推荐