After updating to Python 3.12, I get warnings about invalid escape sequence on some triple-quotes comments.
Is this a new restriction? I have the habit of documenting code using triple-quoted string, but this has never been a problem prior to Python 3.12.
python3 --version
Python 3.12.0
$ ./some_script.py
/some_script.py:123: SyntaxWarning: invalid escape sequence '\d'
"""
I tried replacing all lines with \d
:
20230808122708.445|INFO|C:\dist\work\trk-fullstack-test\namespaces.py
with \\d
:
20230808122708.445|INFO|C:\\dist\work\trk-fullstack-test\namespaces.py
The warning disappears.
Suppressing the warning do not seem to work:
import warnings
warnings.filterwarnings('ignore', category=SyntaxWarning)
Any pointers on how to do this correctly? I hope I do not have to escape all Windows paths documented in triplequotes in our code.
re.compile(r"\d+")
withre.compile("\\d+")
but certainly the problem isn't so much for trivial cases. – Madrid