Learner Algorithm Learner Algorithm - 15 days ago 5
Python Question

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

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 is the 2016.

Thanks to How to get line number in excel sheet using python?

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):
print "row::::: ", row
print "column:: ", column
print "value::: ", sheet.cell(row,column).value

# then I read my file in
df = pd.read_excel(path + filename)


Then I know that I can use something like below to

import time
print("something")
time.sleep(5.5) # pause 5.5 seconds
print("something")


But I could not figure out how to do it without write print , any help is greatly appreciated

Answer

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
Comments