python自动化运维软件测试测试员的那点事

你的Python程序需要进度条

2019-12-27  本文已影响0人  伊洛的小屋

本文首发于伊洛的个人博客:https://yiluotalk.com,欢迎关注并查看更多内容!!!

1. 使用 Progress
(yiluo) ➜  ~ pip install progress
Collecting progress
  Downloading https://files.pythonhosted.org/packages/38/ef/2e887b3d2b248916fc2121889ce68af8a16aaddbe82f9ae6533c24ff0d2b/progress-1.5.tar.gz
Installing collected packages: progress
    Running setup.py install for progress ... done
Successfully installed progress-1.5
# 伊洛Yiluo 
# https://yiluotalk.com

import time
from progress.bar import IncrementalBar

bar_list = [1, 2, 3, 4, 5, 6, 7, 8]

bar = IncrementalBar('progress bar', max=len(bar_list))


if __name__ == '__main__':
    for i in bar_list:
        bar.next()
        time.sleep(1)

    bar.finish()
(yiluo) ➜  AllDemo python demo.py
progress bar |████████████                    | 3/8

2. 使用 Tqdm
pip install tqdm
Collecting tqdm
  Downloading https://files.pythonhosted.org/packages/8c/c3/d049cf3fb31094ee045ec1ee29fffac218c91e82c8838c49ab4c3e52627b/tqdm-4.41.0-py2.py3-none-any.whl (56kB)
     |████████████████████████████████| 61kB 239kB/s
Installing collected packages: tqdm
Successfully installed tqdm-4.41.0
# 伊洛Yiluo
# https://yiluotalk.com

import time
from tqdm import tqdm

_bar = [1, 2, 3, 4, 5, 6, 7, 8]


for item in tqdm(_bar):
    time.sleep(1)
(yiluo) ➜  AllDemo python demo.py
 62%|█████████████████████████████████▊                    | 5/8 
3. 使用 Alive Progress
4. 使用 Pysimplegui(GUI)
(yiluo) ➜  ~ pip install pysimplegui
Collecting pysimplegui
  Downloading https://files.pythonhosted.org/packages/22/a8/ec06b5ce8997411c542dc0f65848a89b6f852b1b9c0fde8ace89aec6703e/PySimpleGUI-4.14.1-py3-none-any.whl (288kB)
     |████████████████████████████████| 296kB 286kB/s
Installing collected packages: pysimplegui
Successfully installed pysimplegui-4.14.1
# 伊洛Yiluo
# https://yiluotalk.com

import PySimpleGUI as sg
import time
bar_list = [1, 2, 3, 4, 5, 6, 7, 8]

for i, item in enumerate(bar_list):
    sg.one_line_progress_meter('我是进度条!', i+1, len(bar_list), 'key')
    time.sleep(1)

欢迎下方【戳一下】【点赞】
Author:伊洛Yiluo
愿你享受每一天,Just Enjoy !

上一篇 下一篇

猜你喜欢

热点阅读