how can I read each line of a xls file with pausing

前端 未结 2 1888
难免孤独
难免孤独 2021-01-21 10:24

I have a xls file on my desktop in mac which has many row (each row consists of a word). what I want is to show each line for 3 minutes in terminal. note that the version of xls

相关标签:
2条回答
  • 2021-01-21 10:42

    do it in this way on Mac

    import time
    import pandas as pd
    import os
    import xlrd
    # at first I try to know how many rows and how many columns I have 
    workbook = xlrd.open_workbook('myfile.xls')
    for sheet in workbook.sheets():
        for row in range(sheet.nrows):
            for column in range(sheet.ncols):
                os.system('clear')
                print "value::: ", sheet.cell(row,column).value
                time.sleep(5.5)    # pause 5.5 seconds
    
    0 讨论(0)
  • 2021-01-21 10:51

    If I understand this correctly, your problem is that you want a line to show up on the terminal for some time, but get hidden when the next one shows up. You can try this for python3 (see the accepted answer for earlier versions):

    import time
    import subprocess
    
    import pandas as pd
    import xlrd
    # at first I try to know how many rows and how many columns I have 
    workbook = xlrd.open_workbook('myfile.xls')
    for sheet in workbook.sheets():
        for row in range(sheet.nrows):
            for column in range(sheet.ncols):
                subprocess.run(["clear"])
                print "row::::: ", row
                print "column:: ", column
                print "value::: ", sheet.cell(row,column).value
                time.sleep(5.5)    # pause 5.5 seconds
    

    clear is generally for Unix though, if it does not work on a Mac, this answer can be helpful.

    0 讨论(0)
提交回复
热议问题