2 hours ago · Tech · hide · 0 comments

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…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.