Why are there both sre and re-modules in Python?

I always assumed that when I saw people mention the sre module, it was a typo and they really meant re .

Today I accidentally typed import sre in the interpreter and was surprised that it worked. I decided to go a little deeper into the fact that the sre module went through help(sre) and ... everything he does is exactly the same as re .

Why do both modules exist? What was the first? Why was the second created? Is someone obsolete and / or remote (has he already left for Python 3? I don't have a Python 3 interpreter on this computer).

+6
source share
1 answer

Yes, it is out of date. When you did help(sre) , you should have seen this line:

 DESCRIPTION This file is only retained for backwards compatibility. It will be removed in the future. sre was moved to re in version 2.5. 

Therefore, it is used for code that is designed for Python <2.5, but now it is being replaced by re .

In addition, it has been removed:

 # Python 3 >>> import sre Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'sre' 
+4
source

All Articles