简体   繁体   English

如何在 python 脚本中显示进度?

[英]how to show progress in a python script?

I need a simple output to show progress in my python script我需要一个简单的 output 来显示我的 python 脚本的进度

eg I have this script例如我有这个脚本

def delete_id(list):
 r = del(id)
 print(r.json())

list = get_list()
 delete_id(list)

There are a few issues with your script.您的脚本存在一些问题。 You don't want to use list or id as variable names because they are built in functions.您不想使用listid作为变量名,因为它们是内置函数。 But you can use Enlighten and do something like this:但是您可以使用Enlighten并执行以下操作:

import enlighten

items = get_list()
pbar = enlighten.Counter(total=len(items))

for id_ in pbar(items):
    delete_id(id_)

If you want to do something more complicated, like have multiple progress bars, you'll want to create a manager first.如果你想做一些更复杂的事情,比如有多个进度条,你需要先创建一个管理器。

manager = enlighten.get_manager()
pbar = manager.counter()

Lot of customization and examples in the docs .文档中的大量自定义和示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM