I have always assumed that when I saw people mention the sre
module, it was a typo and they actually meant re
.
Today, I accidentally typed import sre
into the interpreter and was surprised that it worked. I decided to dig a bit more into what the sre
module was via help(sre)
and... everything about what it does is the exact same as re
.
Why do both modules exist? Which came first? Why was the second created? Is one getting deprecated and/or removed (is it already gone in Python 3? I don't have a Python 3 interpreter on this computer to check with.)
Yes, it is deprecated. When you did help(sre)
, you must 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.
So it's used for code that is designed for Python <2.5, but it is now replaced by re
.
Furthermore, it was removed:
# Python 3
>>> import sre
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'sre'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With