程序运行时打印闪烁点

发布于 2025-01-16 13:09:33 字数 1436 浏览 2 评论 0原文

大家好,我有一个函数可以操作该数据,然后将输出写入 Excel 文件。我想在程序运行时以某种方式在 anaconda powershell promt 中打印一些文本,后跟三个闪烁的点,然后打印另一个文本,例如“进程完成!”当程序完成时。

这是我的代码的一部分,在程序加载时我需要在其中出现闪烁的文本

    def report():
    
    file=int(input('Choose file :'))
    
    if file==1:
        print('')
        print('Creating Report ......')
        print('')
        path2=desktop+'/test'
        if len(os.listdir(path2))>0:
    
            all_files2 = glob.glob(path2 + "/*.xlsx")
            li2=[]
        for i, filename in enumerate(all_files2):
            dfp = pd.read_excel(filename,header=2)
            dfp.drop(dfp.tail(1).index,inplace=True)
            dfp.drop(dfp.columns[0],axis=1,inplace=True)
            dfp.insert(loc=0,column='Date',value=dt)
            dfp.insert(loc=1,column='Hrs',value=str(i+1) +'. '+ os.path.basename(filename).split('.')[0])
            li2.append(dfp)
       framep = pd.concat(li2, axis=0, ignore_index=True)
       book=load_workbook(desktop+'/template.xlsx')
       writer =pd.ExcelWriter(desktop+'Report-'+dt+'.xlsx', engine='openpyxl')
       writer.book = book
       writer.sheets = {ws.title: ws for ws in book.worksheets}
       framep.to_excel(writer,sheet_name='Progressive',startrow=1,index = False,header= False)
    
       writer.save()
  while True:
      Real_time_games()
      if input("Do you want to create another report ? (Y/N) :").strip().upper() != 'Y':
          break 

Hello everyone i have a function that manipulates that data and then writes output to an excel file. I would like to somehow print some text in the anaconda powershell promt followed by three blinking dots while the programm runs and then print another text like "Process completed!" when the programm finishes.

This is part of my code, somewhere inside which i need the blinking text to appear while programm is loading

    def report():
    
    file=int(input('Choose file :'))
    
    if file==1:
        print('')
        print('Creating Report ......')
        print('')
        path2=desktop+'/test'
        if len(os.listdir(path2))>0:
    
            all_files2 = glob.glob(path2 + "/*.xlsx")
            li2=[]
        for i, filename in enumerate(all_files2):
            dfp = pd.read_excel(filename,header=2)
            dfp.drop(dfp.tail(1).index,inplace=True)
            dfp.drop(dfp.columns[0],axis=1,inplace=True)
            dfp.insert(loc=0,column='Date',value=dt)
            dfp.insert(loc=1,column='Hrs',value=str(i+1) +'. '+ os.path.basename(filename).split('.')[0])
            li2.append(dfp)
       framep = pd.concat(li2, axis=0, ignore_index=True)
       book=load_workbook(desktop+'/template.xlsx')
       writer =pd.ExcelWriter(desktop+'Report-'+dt+'.xlsx', engine='openpyxl')
       writer.book = book
       writer.sheets = {ws.title: ws for ws in book.worksheets}
       framep.to_excel(writer,sheet_name='Progressive',startrow=1,index = False,header= False)
    
       writer.save()
  while True:
      Real_time_games()
      if input("Do you want to create another report ? (Y/N) :").strip().upper() != 'Y':
          break 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆一缕阳光ご 2025-01-23 13:09:33

一种选择是使用 tqdm。这需要添加一个 tqdm 包装器。

# add this to the imports
from tqdm import tqdm 

# rest of your code skipped

# wrap any iterations in tqdm
for i, filename in tqdm(enumerate(all_files2)):
    # rest of your code skipped

这将给出一个格式良好的进度条。还可以在代码中的任意点添加一些手动定义的进度条步骤,请参阅此答案

One option is to use tqdm. This will require adding a tqdm wrapper.

# add this to the imports
from tqdm import tqdm 

# rest of your code skipped

# wrap any iterations in tqdm
for i, filename in tqdm(enumerate(all_files2)):
    # rest of your code skipped

This will give a nicely formatted progress bar. It's also possible to add some manually-defined progress bar steps at arbitrary points in your code, see this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文