I have been playing around with the improved regex module for Python by Matthew Barnett and found a strange error (behaviour? bug?).
Consider the following code:
import regex as re
string = "liberty 123, equality 123, fraternity 123"
rx = r'\d+(?=,|$)'
results = re.findall(rx, string)
print (results)
When invoked from the command line on my Mac (python regex.py), I get the error AttributeError: 'module' object has no attribute 'findall', while when I copy and paste the exact same code to the python shell, it correctly outputs
['123', '123', '123']
Can somebody enlight me please? Is this some obvious thing I am missing here?
regex.pyyour file? Did you name it the exact same name as the python package you're trying to import? I'm guessing that it's actually importing itself, which doesn't containfindall()regexthat you are importing. Change the filename, and you should be good.