title: comparing strings and decoded unicode in python3
body: <p>I'm doing some socket/select programming and one of my events is triggered by the incoming byte string of <code>'OK'</code>. I'm using utf_8 to encode everything sent from the server and decoding it on the client. However, my client comparisons aren't working and my if statement never evaluates to true. Here is the code in question:</p>
  
  <p>Server side:</p>
  
  <pre><code>def broadcast_string(self, data, omit_sock): # broadcasts data utf_8 encoded to all socks
      for sock in self.descriptors:
          if sock is not self.server and sock is not omit_sock:
              sock.send(data.encode('utf_8'))
      print(data)
  
  def start_game(self): # i call this to send 'OK'
      data = 'OK'
      self.broadcast_string(data, 0)
      self.new_round()
  </code></pre>
  
  <p>Client side:</p>
  
  <pre><code>else:   # got data from server
      if data.decode('utf_8') == 'OK': # i've tried substituting this with a var, no luck
          self.playstarted = True
      else:
          sys.stdout.write(data.decode('utf_8') + "\n")
          sys.stdout.flush()
  
      if self.playstarted is True: # never reached because if statement never True
          command = input("--&gt;")
  </code></pre>
  
  <p>I've read <a href="http://diveintopython3.org/strings.html#byte-arrays" rel="nofollow">this</a> and I think I'm following it but apparently not. I've even done the examples using the python shell and have had them evaluate to <code>True</code>, but not when I run this program.</p>
  
  <p>Thanks!</p>