看板 Python 關於我們 聯絡資訊
我用判斷回傳的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
chaogold:這樣不會有runtime error阿? 11/22 23:06
okd:真的 這個例子沒有耶 我在寫時遇到兩三次 我再看看 11/22 23:15
okd:找不回錯誤了 抱歉擔誤大家時間 11/22 23:19