Python Forum
octal encoding - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: octal encoding (/thread-6708.html)



octal encoding - Skaperen - Dec-04-2017

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>



RE: octal encoding - wavic - Dec-04-2017

'\007'


RE: octal encoding - DeaD_EyE - Dec-04-2017

b'\377' == b'\xff' and int('0o377', 8) == 0o377 == 0xff == 255


RE: octal encoding - wavic - Dec-04-2017

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



RE: octal encoding - Skaperen - Dec-06-2017

(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.