Python: fix SyntaxWarning: invalid octal escape sequence 0 ▲ Adam Johnson 114 days ago · Tech · hide · Fediverse post Take this code: path = "C:\477_data" If we run this with Python 3.11+ in development mode (to enable deprecation warnings), we will see: $ python3.11 -X dev example.py /.../example.py:1: DeprecationWarning: invalid octal escape sequence '\477' path = "C:\477_data" On Python 3.12+, we instead get a SyntaxWarning which happens at compile time, even without development mode. We can see this by compiling the file with py_compile rather than running it: $ python3.12 -m py_compile example.py example.py:1: SyntaxWarning: invalid octal escape sequence '\477' path = "C:\477_data" So, what does this warning mean? Python strings support octal escape sequences: a backslash followed by one to three octal digits (0–7), such as \120, which represents the character with that codepoint. Three octal digits can encode any value from 0 to 0o777 (511 in decimal), but octal escapes were only ever intended to cover single bytes, 0 to 0o377 (255 in decimal), the range used by earlier character sets like… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town