def encode_string(string):
 if isinstance(string, text_type):
  string = string.encode('utf-8')
 return string

def encode_string ( string ) : if isinstance ( string , text_type ) : string = string . encode ( 'utf-8' ) return string
encodes a string to bytes .