escapingpyserialunicode-escapes

Best way to replace ESC STX SOH characters without changing original data?


I am looking for replacing ESC, STX, SOH with empty space. These characters getting printed alongside original data as shown in the attached image. enter image description here


Solution

  • Step-1: First matched the hex byte characters output to below ASCII chart: enter image description here

    Step-2: Then created the list for badData = [SOH=1,ETX=3,ENQ=5,ESC=1B]

    Step-3: Implemented the list(filter(lambda x: x not in badData, goodData)) with lambda function to filter out the escape characters.

    Step-4: Decode() the goodData