1

我为 docx 文件的一些操作开发了一个脚本。由于 docx 中的巨大过程,该脚本需要 5 到 20 秒来执行输出。因此,到那时用户会混淆脚本是否正在运行。为此,我决定放一个动画,然后就完成了。问题是重复。

看起来像

在此处输入图像描述

我不想重复打印“请稍候...”。我的需要是“请稍候......”应该打印一次,直到完成之后“进程等待......”应该消失。我正在使用python 3。

这是我的代码:

import glob
from docx import Document
import sys
import time
import threading

class Spinner:
    busy = False
    delay = 0.1

    @staticmethod
    def spinning_cursor():
        while 1: 
            for cursor in 'Please Wait...': yield cursor

    def __init__(self, delay=None):
        self.spinner_generator = self.spinning_cursor()
        if delay and float(delay): self.delay = delay

    def spinner_task(self):
        while self.busy:
            sys.stdout.write(next(self.spinner_generator))
            time.sleep(self.delay)
    def start(self):
        self.busy = True
        threading.Thread(target=self.spinner_task).start()

    def stop(self):
        self.busy = False
        time.sleep(self.delay)
i = 0
j=0


spinner = Spinner()
spinner.start()

for name in glob.glob('Test_Plan/*.docx'):
 doc=Document(name)
 for t in doc.tables:
    for ro in t.rows:
        if ro.cells[0].text=="ID" :
            i=i+1
print("Total Number of Tables: ", i)
spinner.stop()

for name in glob.glob('Test_Plan/*.docx'):
    doc=Document(name)
    for table in doc.tables:
     for ro in table.rows:
        if ro.cells[0].text=="Automated Test Case" and (ro.cells[2].text=="yes" or ro.cells[2].text=="Yes"):
            j=j+1
print("Total Number of YES Automations: ", j)

k = 0
for name in glob.glob('Test_Plan/*.docx'):
    doc=Document(name)
    for t in doc.tables:
     for ro in t.rows:
        if ro.cells[0].text=="Automated Test Case" and (ro.cells[2].text=="no" or ro.cells[2].text=="No"):
            k=k+1
print("Total Number of NO Automations: ", k)
4

0 回答 0