Python SyntaxWarning error Xubuntu 24.04
Opened this issue · 1 comments
I just built a new VM with Xubuntu 24.04. I changed the shebang to point to python3, but I get a new error (didn't get this error in Xubuntu 22.04):
/usr/local/bin/movescreen.py:49: SyntaxWarning: invalid escape sequence '+'
reg = re.compile(" connected( primary)? ([0-9]+)x([0-9]+)+([0-9]+)+([0-9]+)")
Not being a Python programmer, I don't know what changed. Python version is 3.12.3.
I could not try yet with more recent python versions but after searching a bit, the solution might be :
Change the original line:
reg = re.compile(" connected( primary)? ([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)")
to (double the backslahs):
reg = re.compile(" connected( primary)? ([0-9]+)x([0-9]+)\\+([0-9]+)\\+([0-9]+)")
or maybe (declare the string as raw):
reg = re.compile(r" connected( primary)? ([0-9]+)x([0-9]+)\\+([0-9]+)\\+([0-9]+)")