title: Comparing UTF8 strings in python
body: <p>I want to check that if the argumant <em>s</em> of function <em>f1(s)</em> receives some strings (that are in UTF8 ) in <em>MyList</em> then call function <em>f2</em>; But I cannot compare strings correctly.</p>
  
  <pre><code>def f1( s ):
      MyList = [ u"نامشخص".encode("utf-8") , u"Unknow".encode("utf-8")]
      for t in MyList:
          if( t == s.encode('utf-8') ):
              f2()
              return None
              break
          else:
              print "Checked strings: ",  t , " =?=" , s.encode("utf-8")
              print "Checked strings length: ", len(t),  " =?=" , len(s)
      return s
  </code></pre>
  
  <p>Checking:</p>
  
  <pre><code>MyList2 = [ u"نامشخص" , "test2".encode("utf-8"), u"نامشخص".encode("utf-8") ]
  
  for a in MyList2:
      print "Test String = ", a
      f1(a)
      print "\n\n"
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code> Test String =  نامشخص
   Here[=]
  
  
  
  Test String =  test2
  Checked strings:  نامشخص  =?= test2
  Checked strings length:  12  =?= 5
  
  Checked strings:  Unknow  =?= test2
  Checked strings length:  6  =?= 5
  
  
  
  Test String =  نامشخص
  Traceback (most recent call last):
    File "test.py", line 31, in &lt;module&gt;
      f1(a)
    File "test.py", line 18, in f1
      if( t == s.encode('utf-8') ):
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xd9 in position 0: ordinal not in range(128)
  </code></pre>
  
  <p>Infact I receive string <em>s</em> from sqlite db and I don't know the encoding of <em>s</em>. 
  It is intersting that for some string <em>s</em> from db <em>f1</em> mistakes without error!
  It seems <em>f1</em> works only for some specified encodings. Is there any solution that works for all encoding for string <em>s</em>?</p>