Python Forum
Python Struct Question, decimal 10, \n and \x0a.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Struct Question, decimal 10, \n and \x0a.
#2
(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.
3python and Gribouillis like this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Python Struct Question, decimal 10, \n and \x0a. - by DeaD_EyE - Aug-11-2023, 08:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use a variable in Python (2.x) to define decimal part? MDRI 4 2,422 May-07-2021, 12:39 AM
Last Post: MDRI
  JS Buffer.from VS struct.pack DreamingInsanity 3 2,584 Apr-05-2021, 06:27 PM
Last Post: DreamingInsanity
  struct.unpack failed Roro 2 3,463 Jun-13-2020, 05:28 PM
Last Post: DreamingInsanity
  Pack integer values as single bytes in a struct bhdschmidt 3 2,455 Jun-09-2020, 09:23 PM
Last Post: bhdschmidt
  struct.decode() and '\0' deanhystad 1 3,346 Apr-09-2020, 04:13 PM
Last Post: TomToad
  python decimal scale precision massimo_m 5 5,599 Aug-22-2019, 11:47 AM
Last Post: perfringo
  How to remove empty struct from matlab file in python? python_newbie09 0 2,447 Jun-25-2019, 12:13 PM
Last Post: python_newbie09
  testing for Decimal w/o importing decimal every time Skaperen 7 4,605 May-06-2019, 10:23 PM
Last Post: Skaperen
  Python 2 to Python 3 Struct Issue robin73 5 6,482 Jun-16-2018, 10:47 PM
Last Post: robin73
  Error in Python 3.6 and how to limit decimal places Raptor88 6 10,010 Mar-18-2017, 05:02 AM
Last Post: Raptor88

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020