本文介绍了向python函数添加进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢对初学者的任何帮助:) 我尝试了以下方法但不确定如何包装 def Job():
Appreciate any help for a beginner :) I tried the below but not sure how to wrap the def Job():
import time from progressbar import ProgressBar pbar = ProgressBar() def job(): Script .... Script ... Script ... Script ... 推荐答案你可以这样使用 bar 对象:
You can use the bar object this way:
import time import progressbar def job(): bar = progressbar.ProgressBar() for i in bar(range(100)): ... # Code that you want to run #time.sleep(0.02) job()如果你要执行的代码执行时间很快,你可以在里面放一个time.sleep(),以免在开始时progressbar设置为100%.
If the code you want to execute has fast execution time, you can put a time.sleep() inside in order not to have progressbar set to 100% in the beginning.
更多推荐
向python函数添加进度条
发布评论