我有以下字符串:
u'>>\n> yes\n>'
以及以下函数,以搜索“是”或“y”:
def checkformatch(search_str):
to_find = re.compile(r'\b(yes|y)\b')
match_obj = to_find.search(search_str.lower)
which_word_matched = match_obj.group() if match_obj else ''
return which_word_matched
据我所知,什么也没有归还。当我在pycharm调试器中单步执行此操作时,它似乎没有到达return语句(非常奇怪的行为)
我做错什么了
您的代码在
match_obj = to_find.search(search_str.lower)
行上抛出一个TypeError: expected string or buffer
lower()
is a method,您需要调用它:相关问题 更多 >
编程相关推荐