Python Progress Bar

后端 未结 30 2591
礼貌的吻别
礼貌的吻别 2020-11-22 06:13

How do I use a progress bar when my script is doing some task that is likely to take time?

For example, a function which takes some time to complete and returns

30条回答
  •  一整个雨季
    2020-11-22 06:56

    You can use tqdm:

    from tqdm import tqdm
    
    with tqdm(total=100, desc="Adding Users", bar_format="{l_bar}{bar} [ time left: {remaining} ]") as pbar:
        for i in range(100):
            time.sleep(3)
            pbar.update(1)
    

    In this example the progress bar is running for 5 minutes and it is shown like that:

    Adding Users:   3%|█████▊                                     [ time left: 04:51 ]                                                                                                        
    

    You can change it and customize it as you like.

提交回复
热议问题