99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2021-01-28 閱讀量: 2256
正則表達(dá)式中出現(xiàn)AttributeError: 'NoneType' object has no attribute 'group'問題

在運(yùn)用正則表達(dá)式做匹配的過程中可能會(huì)出現(xiàn)如:AttributeError: 'NoneType' object has no attribute 'group'的錯(cuò)誤,這主要是由于沒有匹配到元素,之后又調(diào)用了group()方法造成的。

import recontent = 'hello world'result = re.match('^w.*d$', content)#這是想只提取worldprint(result)print(result.group())

第一個(gè)print函數(shù)會(huì)打印none,因?yàn)閙atch函數(shù)只能從頭開始匹配,不能從中間開始。而當(dāng)返回值為none時(shí),再次調(diào)用group()方法就會(huì)出現(xiàn)AttributeError: 'NoneType' object has no attribute 'group'這類報(bào)錯(cuò)。

將上述代碼塊中的match改成search()就可以避開這類問題了。search函數(shù)是先掃描全部的代碼塊,再進(jìn)行提取的。


1.1095
0
關(guān)注作者
收藏
評(píng)論(0)

發(fā)表評(píng)論

暫無數(shù)據(jù)
推薦帖子