python:由循环"unexpected indent error"中的正则表达式生成的数组



当我运行以下代码时,出现错误"IdentationError:意外缩进"。但我不知道为什么以及如何解决它。错误在第一个 if 语句中。

import re
import xlrd
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
UOB = [sheet.cell_value(r,14) for r in range(sheet.nrows)]
count = {}
Myset = set()
for x in range (sheet.nrows):
    match = re.findall(",*([w]*[College]*[Department]*[w ]*),[ ]        
[The]*Uni[w.]*[ ]of[ ]Bahr[ai]*[ei]*n,*([w ]*[College]*[Department]*[w ]*),",UOB[x])
    if match[0][0]!='':
        if match[0][0] in Myset:
            count[match[0][0]]+=1  
        else:   
            Myset.add(match[0][0])
            count[match[0][0]]=1
    else:
        if match[0][1] in Myset:
            count[match[0][1]]+=1  
        else:   
            Myset.add(match[0][1])
            count[match[0][1]]=1

字符串设置为变量并清理它以正确适应多行:

z = (   ",*([w]*[College]*[Department]*[w ]*),"     +
        "[ ][The]*Uni[w.]*[ ]of[ ]Bahr[ai]*[ei]*n,"  +
        "*([w ]*[College]*[Department]*[w ]*),"     )
for x in range (sheet.nrows):
    match = re.findall(z,UOB[x])

最新更新