def encode_utf8(string):
 if isinstance(string, unicode):
  try:
   return string.encode('utf-8')
  except:
   return string
 return str(string)

def encode_utf8 ( string ) : if isinstance ( string , unicode ) : try : return string . encode ( 'utf-8' ) except : return string return str ( string )
encode a utf-8 string to a sequence of bytes .