作者okd (...)
看板Python
标题[问题] 比较是不是None 不是就读
时间Sun Nov 22 22:59:00 2009
我用判断回传的instance去判断re它有没有match
没有match的话 便执行下面的else
但是像下面例子会出现runtime error
说没有test.group(0) 可是感觉这行应该不会执行到
应该是我观念哪里错了 请问有人可以指导一下吗 谢谢
Example:
import re
test=re.search('abc','def')
if test!=None:
print test.group(0)
else:
print 'no match'
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.123.216.148
1F:→ chaogold:这样不会有runtime error阿? 11/22 23:06
2F:→ okd:真的 这个例子没有耶 我在写时遇到两三次 我再看看 11/22 23:15
3F:→ okd:找不回错误了 抱歉担误大家时间 11/22 23:19