【发布时间】:2014-02-01 14:36:16
【问题描述】:
我正在研究我在What's the most efficient way to find one of several substrings in Python? 上找到的一些示例代码。我已将代码更改为:
import re
to_find = re.compile("hello|there")
search_str = "blah fish cat dog haha"
match_obj = to_find.search(search_str)
#the_index = match_obj.start()
which_word_matched = ""
which_word_matched = match_obj.group()
由于现在没有匹配,我得到:
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
python中处理不匹配场景的标准方法是什么,以避免错误
【问题讨论】: