3

I wanted to import the re module to do some web scraping.
I wrote down the 'import re' function and got this message:

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. If the problem is due to this, then how do I install the module back? Thanks.

Klaus D.
  • 13,874
  • 5
  • 41
  • 48
  • 2
    You called your module `re`, if you are trying to import `re` from the standard lib now there will be a name clash. – Klaus D. Dec 08 '19 at 03:59

1 Answers1

2

I think you are trying import re module in a .py file named 're.py'.
In this way, a name clash occurs.So why not change the name of the .py file into my_re.py?

Liang Fan
  • 81
  • 4