(string)
Ensure a string is returned as a bytes object, encoded as utf8.
Ensure a string is returned as a bytes object, encoded as utf8.
Ensure a string is returned as a bytes object encoded as utf8 .
def ensure_bytes(string):
    """Ensure a string is returned as a bytes object, encoded as utf8."""
    if isinstance(string, unicode):
        return string.encode("utf8")
    else:
        return string
def ensure_bytes ( string ) : if isinstance ( string , unicode ) : return string . encode ( "utf8" ) else : return string