Traceback (most recent call last): File "AttributeError: 'NoneType' object has no attribute 'group'

版权声明:转载请声明原文链接地址,谢谢! https://blog.csdn.net/weixin_42859280/article/details/84400623
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'

标题太长,放不下。这里再说一遍。

失败的情况:
在这里插入图片描述

>>> m = re.search(r'PY.*N', 'FBHNS')
>>> m.group(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'

这个是因为,没有一个可以成功进行匹配的。
前面的单词开头:*PY.N 匹配的必须是:PY开头的短语!然而,被匹配的短语是:FBHNS。所以会匹配失败!

改正后成功的一次:
在这里插入图片描述
代码如下:

>>> m = re.search(r'PY.*N', 'PYGUHNCWDJCNSDXS')
>>> m.group(0)
'PYGUHNCWDJCN'
>>>

前面的单词开头:*PY.N 匹配的必须是:PY开头的短语!然而,被匹配的短语是:PYGUHNCWDJCNSDXS。所以会匹配成功!

所有尝试:
80Mjg1OTI4MA==,size_16,color_FFFFFF,t_70)

猜你喜欢

转载自blog.csdn.net/weixin_42859280/article/details/84400623