0

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 
  • If it's only about presenting that program isn't stuck/is still working, how about printing current file name/path being worked with? Or printing next dot? For bigger files it still maybe a issue tho I guess – AgainPsychoX Mar 22 '22 at 13:41

1 Answers1

0

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.

SultanOrazbayev
  • 14,900
  • 3
  • 16
  • 46