5
votes

I am trying to use the following python module:

import re
test = 'some text'
find = re.findall(r'text', test)
print(find)

When i try to run it in sublime, it writes:

AttributeError: module 're' has no attribute 'findall'

If i try to run it in Cygwin, there is a message:

AttributeError: 'module' object has no attribute 'findall'

But if i use attibute "findall" in python console, it works without any problem. I really don't undestand, what's wrong. In Sublime i use python 3.5.1, cygwin uses python 3.4.3, as i remember.

2
Is it possible that you have a file called re.py ? - khelwood
I try to execute the file with this name. It can cause the error? - mrser
Let me rephrase. If you have a file named re.py it may screw up your importing of the module re. Don't name a file re.py. - khelwood
Wow, i am pretty stupid. Thank you, i renamed the file, and now it works. - mrser

2 Answers

19
votes

If you have a file called re.py, then when you try and import re, Python may look inside that file instead of inside the standard module re. So don't name a file re.py (or the name of any other module you want to import).

0
votes

I had the same problem. do not name any file or pragram as same as module name.

ex. re.py (do not name any file with this name)