title: Python (pySerial): cannot trim/remove CR, LF or unexpected characters from string
body: <p>I am using an Arduino to output Temp &amp; Hum data from a sensor, this is being read by a PC running Python using pySerial.  The data is reading in correctly but I would like to remove the CR/LF and unexpected characters.  One idea I found on this site was to use lstrip or lreplace but they do not seem to work correctly.  They will remove one instance of the character but even repeating the line or making a small loop has no effect.  </p>
  
  <p>This is what the program Prints (Bottom line is string after I've tried to cut out the unnecessary characters):</p>
  
  <blockquote>
    <p>[b'\n', b'\r\n', b'Read sensor: OK\r\n', b'Hum40.00\r\n', b'TempC18.00\r\n']</p>
    
    <p>[" b'Hum40.00\r\n'", " b'TempC18.00\r\n']"]</p>
  </blockquote>
  
  <p>I am aiming for it to read:</p>
  
  <blockquote>
    <p>[Hum40.00, TempC18.00]</p>
  </blockquote>
  
  <p>I can hopefully fine tune the message later.</p>
  
  <p>This is the code:</p>
  
  <pre><code>    import serial as ser
      import time
  
      count = 0
      msgArray = []
      saveMsg = []
  
      ser = ser.Serial('COM16', 9600, timeout=1, parity='N', stopbits=1,                                bytesize=8, xonxoff=0) # Setting up and opening COM port
      ser.close()
      ser.open()
  
      def readSerial():               #reads a whole line from COM port
          serLine = ser.readline()
          return serLine
  
      def sveMsgCut():                #saves the buffer as a message then cuts message
          cutMsg = saveMsg
          words = cutMsg.split(',')
          return words
  
      while True:                     #main program
          dataSerial = readSerial()
  
          if count &lt; 5:                       #reads COM port 5 times and passes along to buffer msgArray
              msgArray.append(dataSerial)
              count = count+1
          else:
              print(msgArray)                     #~display msgArray
              saveMsg = str(msgArray)             #convert to string
              splitMsg = saveMsg.split(',')       #splits string (csv)
              phrase = splitMsg[3:5]              #cuts out excess either side of Temp &amp; Hum/
              phraseString = str(phrase)
              phraseNew = phraseString.lstrip("/n") #an attempts ot remove CR
  
              print(phraseNew)                    #~print adjusted string
  
              saveMsg = msgArray
              count = 0       #resets msgArray and counter
              msgArray = []
  
  
  
              time.sleep(5)
  </code></pre>
  
  <p>I am fairly new to programming, especially Python so it may be something simple that I've missed but have tried several different ideas and cannot remove the extra characters.</p>