乐趣区

python练习时出现module ‘re’ has no attribute ‘match’错误

练习 python 中正则表达式,使用 import re,并且写了最简单的匹配,运行 py 文件,却提示 module ‘re’ has no attribute ‘match’ 错误。

仔细查看原因,原来是自己把 python package 写成了 re 了。

导致 python 在执行 import re 时,以为我们要他导入我自己定义的 package 呢,将包名字改成 retest,重新运行 py 文件,成功运行。

退出移动版