Python xlrd字符串与单元格的比较

时间:2012-05-10 09:40:59

标签: python excel xlrd

我是Python& xlrd和我在执行(看似)简单的字符串比较时遇到了问题:

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"

当我通过解释器运行代码时,出现以下错误:

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

我错过了什么或做错了什么?我正在比较两个字符串,对吧?

1 个答案:

答案 0 :(得分:1)

信任口译员并阅读docs

更改

if col.lower() == "apple"

if col.lower() == "apple":
相关问题