AttributeError: 'module' object has no attribute 'fullmatch'.

来源:互联网 发布:武汉淘宝美工培训学校 编辑:程序博客网 时间:2024/06/06 14:26

报错

跑代码的时候遇到了 AttributeError

AttributeError: 'module' object has no attribute 'fullmatch'.

经过查找,发现出错的原因是 re库 中的 fullmatch函数在py3.4之后才新添加的

解决方案

自己写一个接口,然后调用该接口即可。

一般会把自己新写的接口放在 utils.py 文件里。在该文件中加上以下代码段:

import re# Backport Python 3.4's regular expression "fullmatch()" to Python 2def fullmatch(regex, string, flags=0):    """Emulate python-3.4 re.fullmatch()."""    return re.match("(?:" + regex + r")\Z", string, flags=flags)

接着在原本 调用 re.fullmatch 接口 的地方 替换 为 调用 utils.fullmatch 接口 即可。



阅读全文
0 0