def compat_str(s):
 if isinstance(s, str):
  return s
 elif isinstance(s, bytes):
  return s.decode('utf-8')
 else:
  return str(s)

def compat_str ( s ) : if isinstance ( s , str ) : return s elif isinstance ( s , bytes ) : return s . decode ( 'utf-8' ) else : return str ( s )
detect if s is a string and convert it to unicode if it is bytes .