AttributeError: ‘NoneType‘ object has no attribute ‘span‘
span 是返回配置到内容的下标,使用span 的时候需要注意,当匹配不到内容的时候就会报错了,
如下的例子就会报错
str_content = "Python is a good language"
re_content = re.match("python", str_content).span()
print(re_content)
所以修改下要匹配的内容即可
如下main的就不会报错了
str_content = "Python is a good language"
re_content = re.match("Python", str_content).span()
print(re_content)
结果如下
还没有评论,来说两句吧...