(s, encoding='utf-8', errors='strict')
return s
Coerce *s* to `str`.

    For Python 2:
      - `unicode` -> encoded to `str`
      - `str` -> `str`

    For Python 3:
      - `str` -> `str`
      - `bytes` -> decoded to `str`
Coerce *s* to `str`.
Coerce * s * to str .
def ensure_str(s, encoding='utf-8', errors='strict'):
    """Coerce *s* to `str`.

    For Python 2:
      - `unicode` -> encoded to `str`
      - `str` -> `str`

    For Python 3:
      - `str` -> `str`
      - `bytes` -> decoded to `str`
    """
    if not isinstance(s, (text_type, binary_type)):
        raise TypeError("not expecting type '%s'" % type(s))
    if PY2 and isinstance(s, text_type):
        s = s.encode(encoding, errors)
    elif PY3 and isinstance(s, binary_type):
        s = s.decode(encoding, errors)
    return s
def ensure_str ( s , encoding = 'utf-8' , errors = 'strict' ) : if not isinstance ( s , ( text_type , binary_type ) ) : raise TypeError ( "not expecting type '%s'" % type ( s ) ) if PY2 and isinstance ( s , text_type ) : s = s . encode ( encoding , errors ) elif PY3 and isinstance ( s , binary_type ) : s = s . decode ( encoding , errors ) return s