AttributeError: ‘NoneType‘ object has no attribute ‘span‘

朱雀 2023-01-21 04:29 180阅读 0赞

span 是返回配置到内容的下标,使用span 的时候需要注意,当匹配不到内容的时候就会报错了,

如下的例子就会报错

  1. str_content = "Python is a good language"
  2. re_content = re.match("python", str_content).span()
  3. print(re_content)

所以修改下要匹配的内容即可

如下main的就不会报错了

  1. str_content = "Python is a good language"
  2. re_content = re.match("Python", str_content).span()
  3. print(re_content)

结果如下

20210514152615201.png

发表评论

表情:
评论列表 (有 0 条评论,180人围观)

还没有评论,来说两句吧...

相关阅读