def to_utf8(obj):
 if isinstance(obj, str):
  try:
   return obj.decode('utf-8')
  except AttributeError:
   return obj
 try:
  if isinstance(obj, unicode):
   return obj
  else:
   return obj.__str__().decode('utf-8')
 except NameError:
  if isinstance(obj, bytes):
   return obj.decode('utf-8')
  else:
   return obj.__str__()

def to_utf8 ( obj ) : if isinstance ( obj , str ) : try : return obj . decode ( 'utf-8' ) except AttributeError : return obj try : if isinstance ( obj , unicode ) : return obj else : return obj . __str__ ( ) . decode ( 'utf-8' ) except NameError : if isinstance ( obj , bytes ) : return obj . decode ( 'utf-8' ) else : return obj . __str__ ( )
return a unicode string representing a python object .