title: TypeError: unicode strings are not supported, please encode to bytes: '\x08'
body: <p>I read this answers: </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/35642855/python3-pyserial-typeerror-unicode-strings-are-not-supported-please-encode-to">python3 pySerial TypeError: unicode strings are not supported, please encode to bytes:</a></li>
  <li><a href="https://stackoverflow.com/questions/39692285/arduino-error-communicating-unicode-strings-are-not-supported-please-encode">Arduino &#39;Error communicating...unicode strings are not supported, please encode to bytes&#39; PySerial</a></li>
  </ul>
  
  <p>But I was not understanding it. In my case I have <code>chr(code)</code> going into the <code>serial.write</code> functions.</p>
  
  <p>Do I write <code>b'chr(8)'</code>?</p>
  
  <pre><code>import serial
  import pygame
  from pygame.locals import *
  
  
  class RCTest(object):
  def __init__(self):
      pygame.init()
      screen = pygame.display.set_mode((400, 300))
      self.ser = serial.Serial('COM3', 9600, timeout = 1)
      self.send_inst = True
      self.steer()
  
  def steer(self):
  
      while self.send_inst:
  
          for event in pygame.event.get():
              print("entered for loop")
  
              if event.type == KEYDOWN:
                  print("entered event.type == KEYDOWN")
  
                  key_input = pygame.key.get_pressed()
                  print("pygame.key.get_pressed() running")
  
                  # complex orders
                  if key_input[pygame.K_UP] and key_input[pygame.K_RIGHT]:
                      print("Forward Right")
                      self.ser.write((chr(6))
  
                  elif key_input[pygame.K_UP] and key_input[pygame.K_LEFT]:
                      print("Forward Left")
                      self.ser.write((chr(4))
  
                  # simple orders
                  elif key_input[pygame.K_UP]:
                      print("Forward")
                      self.ser.write((chr(8))
  
                  elif key_input[pygame.K_DOWN]:
                      print("Reverse")
                      self.ser.write((chr(2))
  
                  # exit
                  elif key_input[pygame.K_x] or key_input[pygame.K_q]:
                      print('Exit')
                      self.send_inst = False
                      self.ser.write((chr(0))
                      self.ser.close()
                      break
  
              elif event.type == pygame.KEYUP:
                  self.ser.write((chr(0))
  
  
  if __name__ == '__main__':
      RCTest()
  </code></pre>
  
  <p>After running the program, I press DOWN ARROWKEY.</p>
  
  <pre class="lang-none prettyprint-override"><code>entered for loop
  entered for loop
  entered for loop
  Traceback (most recent call last):
  entered event.type == KEYDOWN
    File "C:/Users/../rc_control_test.py", line 58, in &lt;module&gt;
  pygame.key.get_pressed() running
      RCTest()
  Reverse
  </code></pre>