Search code examples
pythonexcelxlrd

Python xlrd string comparison against a cell


I am new to Python & xlrd and I am having trouble performing a (seemingly) simple string comparison:

import xlrd

workbook = xlrd.open_workbook('/home/Y725271/Desktop/test_report.xls')
sheet = workbook.sheet_by_index(0)

# Iterate all of the column names and see if col apple exists
col_len = sheet.row_len(0)
for i in range(col_len):
    col = sheet.cell_value(0,i)
    if col.lower() == "apple"
        print "match"
    else
        print "mismatch"

When I run the code through the interpreter, I get the following error:

  File "<stdin>", line 3
    if col.lower() == "apple"
                            ^
SyntaxError: invalid syntax

What am I missing or doing wrong? I'm comparing two strings, right?


Solution

  • Trust the interpreter and read up on the docs

    Change

    if col.lower() == "apple"
    

    into

    if col.lower() == "apple":