0

I am making an excel file reading program in python. I want it to read each cell in a particular column. I used a for loop for this. This is my code:

location = "C:\\Users\\user2\\Desktop\\Python\\Other\\blah.xls"
workbook = xlrd.open_workbook(location)
sheet = workbook.sheet_by_index(0)
rownum = 1
for word in (sheet.cell_value(rownum,2)):
    print(word)
    rownum += 1

And I get the result:

R
E
S
T
A
R
T

I
S
S
U
E

/

R
A
M

P
R
O
B
L
E
M

Instead, I want the result to show word by word, not letter by letter.

1 Answer 1

1

Instead of

for word in (sheet.cell_value(rownum,2)):

Use

for word in (sheet.cell_value(rownum,2).split(' ')):

If you use for on a string, it will iterate over single characters

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.