ahadcse
ahadcse

Reputation: 499

taking data from .xls file to python list

Open the workbook

import xlrd
wb = xlrd.open_workbook('/home/AlAhAb65/Desktop/Parameter.xls')

Check the sheet names

wb.sheet_names()

Get the first sheet either by name

sh = wb.sheet_by_name('QA_TEST')
l = []

Iterate through rows, returning each as a list that you can index:

for rownum in range(sh.nrows):
    l.append(sh.row_values(rownum))
print l

When I am reading from excel to python list there always come ‘u’ before every data. How can I get rid of this? Is everything read as string? Do I have to convert every time?

Upvotes: 0

Views: 135

Answers (1)

wich
wich

Reputation: 17117

The 'u' is not part of the string, it comes before the quotes and indicates a unicode string, which should be fine.

Also, you may want to have a look at the more recent openpyxl.

Upvotes: 1

Related Questions