Aug-11-2023, 08:34 AM
(Aug-11-2023, 06:39 AM)3python Wrote: Why is decimal 10 appearing as \n and not \x0a ? It is after all hex value \x0a.
Python replaces known ASCII characters with their representation as Escape Sequences.
Documentation: https://docs.python.org/3/reference/lexi...l#literals
These special characters are not all printable. The newline character is only shown in the representation of a str/bytes object. Printing a str -> Newline characters creates a newline. Printing bytes with newline -> Newline Character is not interpreted.
If you need a different representation of binary data, then try
binascii.hexlify
and binascii.unhexlify
. Instead of a str with mixed hexadecimal escape sequences and ascii, you get a hexdecimal string.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!