1
我在python for
循环中遇到了问题,跳过if
并跳到else
,因此循环总是返回"none"
,它包含re.match
。 if
将工作,如果我没有别的。为什么我的代码直接跳到其他地方?
下面的代码:
def searchBegin (searchChar):
regex = searchChar
regex += '.{2,7}'
pattern = re.compile(regex)
for (offset, line) in enumerate(lines):
if re.match(pattern, line):
return line
break
else:
return 'none'
我如何纠正呢?