向python函数添加进度条

编程入门 行业动态 更新时间:2024-10-08 22:51:23
本文介绍了向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函数添加进度条

本文发布于:2023-11-26 09:27:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   进度条   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!