title: Is this the best way to ensure that a python unicode "string" is encoded in utf-8?
body: <p>Given in arbitrary "string" from a library I do not have control over, I want to make sure the "string" is a unicode type and encoded in utf-8.  I would like to know if this is the best way to do this:</p>
  
  <pre><code>import types
  
  input = &lt;some value from a lib I dont have control over&gt;
  
  if isinstance(input, types.StringType):
      input = input.decode("utf-8")
  elif isinstance(input, types.UnicodeType):
      input = input.encode("utf-8").decode("utf-8")
  </code></pre>
  
  <p>In my actual code I wrap this in a try/except and handle the errors but I left that part out.</p>