简体   繁体   English

为什么我不能导入 re 模块?

[英]Why can't I import the re module?

I wanted to import the re module to do some web scraping.我想导入 re 模块来做一些网页抓取。
I wrote down the 'import re' function and got this message:我写下了“import re”函数并收到了这条消息:

Traceback (most recent call last):
  File "/Users/willardsun/PycharmProjects/untitled/re.py", line 1, in <module><br>
    import re<br>
  File "/Users/willardsun/PycharmProjects/untitled/re.py", line 2, in <module><br>
    re.compile<br>
AttributeError: partially initialized module 're' has no attribute 'compile' (most likely due to a circular import)

What does this exactly mean?这究竟是什么意思? I checked the binary skeleton and there was no re module.我检查了二进制骨架,没有 re 模块。 If the problem is due to this, then how do I install the module back?如果问题是由于这个原因,那么我如何重新安装模块? Thanks.谢谢。

I think you are trying import re module in a .py file named 're.py'.我认为您正在尝试在名为“re.py”的 .py 文件中导入 re 模块。
In this way, a name clash occurs.So why not change the name of the .py file into my_re.py?这样就发生了名字冲突。那为什么不把.py文件的名字改成my_re.py呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM