0

I need a simple output to show progress in my python script

e.g. I have this script

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

list = get_list()
 delete_id(list)
Tom
  • 1
  • this will help https://stackoverflow.com/questions/3173320/text-progress-bar-in-terminal-with-block-characters – Tom Apr 25 '22 at 14:57
  • 1
    In particular, `tqdm` from jfs's answer is super easy to use. – Amadan Apr 25 '22 at 15:00

1 Answers1

0

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. But you can use Enlighten and do something like this:

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.

aviso
  • 2,371
  • 1
  • 14
  • 15