python报错:'module' object has no attribute 'compile'

代码如下:

import re

pattern = re.compile(r’Hello’)
match = pattern.match(‘Hello cxy61!’)

print match

执行后报错:‘module’ object has no attribute ‘compile’

解决方法:
因为源文件取名为“re.py”,把源文件“re.py”换了个文件名, 不能用跟系统库同样名字.

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
AttributeError: module 're' has no attribute 'compile'这个错误通常是由于导入的模块中没有对应的属性而引起的。在这种情况下,可能是re模块中没有compile属性。这个问题的解决方法是检查你的代码中是否正确导入了re模块,并且确认模块中确实存在compile属性。如果你确定导入和属性使用都正确,那么可能是由于之前生成的.pyc文件存在问题导致的。你可以尝试删除这些.pyc文件,然后重新运行代码。如果问题依然存在,可能需要进一步检查代码逻辑和模块使用方式来解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [attributeError:'module' object has no attribute ** 解决办法](https://blog.csdn.net/diandu3502/article/details/102139862)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Python脚本报错AttributeError: ‘moduleobject has no attribute’xxx’解决方法](https://blog.csdn.net/u011950993/article/details/51454645)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值