Python Forum

Full Version: octal encoding
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
is the explicit octal sequence encoding supposed to be available or not in string literals?
Output:
lt1/forums /home/forums 1> ; bash: syntax error near unexpected token `;' lt1/forums /home/forums 2> py2 Python 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> len('\x07') 1 >>> len('\o007') 5 >>> lt1/forums /home/forums 3> py3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> len('\x07') 1 >>> len('\o007') 5 >>> lt1/forums /home/forums 4>
'\007'
b'\377' == b'\xff' and int('0o377', 8) == 0o377 == 0xff == 255
Python 3.6.3 (default, Oct 24 2017, 14:48:20)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> len('\007')
1
(Dec-04-2017, 09:43 AM)wavic Wrote: [ -> ]'\007'

that's the implicit one.  i'm asking about the explicit one where you specify that it is octal.  and i am asking about what string literals accept, not numeric literals.

i thought string literals would accept explicit octal sequences so i included them in my conversion function.  i guess i am wrong.  i was too confident to RTFM or just test it myself.