Python 3.x 如何在python中剪切动画中的重复字符串

Python 3.x 如何在python中剪切动画中的重复字符串,python-3.x,loading,pleasewait,Python 3.x,Loading,Pleasewait,我已经为docx文件上的一些操作开发了一个脚本。该脚本需要5到20秒来执行输出,因为docx中有巨大的进程。因此,在这段时间内,用户将弄不清楚脚本是否正在运行。为此,我决定放一个动画,我已经完成了。问题在于重复 看起来像 我不想重复打印“请稍候…”。我在这里的需要是,“请等待…”应该打印一次,直到完成进度之后,“进程等待…”应该消失。我正在使用python 3 这是我的代码: import glob from docx import Document import sys import tim

我已经为docx文件上的一些操作开发了一个脚本。该脚本需要5到20秒来执行输出,因为docx中有巨大的进程。因此,在这段时间内,用户将弄不清楚脚本是否正在运行。为此,我决定放一个动画,我已经完成了。问题在于重复

看起来像

我不想重复打印“请稍候…”。我在这里的需要是,“请等待…”应该打印一次,直到完成进度之后,“进程等待…”应该消失。我正在使用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)

向我们展示您的代码可能有助于我们帮助您解决问题。我已经添加了代码。如果您想打印一次,为什么不在开始时使用
print('Please Wait…
)一次?您能解释一下@alperen向我们展示您的代码可能有助于我们帮助您解决问题。我已经添加了代码。如果您想打印一次,为什么不在开始时使用
print('请稍候…
)一次?您能解释一下@Alperen吗