if 문과 함께 파이썬의 정규식을 사용하고 있습니다. 일치 항목이 None
인 경우 else
절로 가야합니다. 그러나이 오류를 보여줍니다파이썬 : if 문 "if not none"처리
AttributeError: 'NoneType' object has no attribute 'group'
스크립트는 다음과 같습니다
import string
chars = re.escape(string.punctuation)
sub='FW: Re: 29699'
if re.search("^FW: (\w{10})",sub).group(1) is not None :
d=re.search("^FW: (\w{10})",sub).group(1)
else:
a=re.sub(r'['+chars+']', ' ',sub)
d='_'.join(a.split())
모든 도움이 큰 도움이됩니다!
당신은'is None'이 아니라'is not'라고 썼습니다. – spies006
첫 번째 오류는 가져 오기 다시입니다 – bigbounty
그 다음에도 작동하지 않습니다 –