def is_bytes ( string ) : if six . PY3 and isinstance ( string , ( bytes , memoryview , bytearray ) ) : # noqa return True elif six . PY2 and isinstance ( string , ( buffer , bytearray ) ) : # noqa return True return False
python check if bytes
Check if a string is a bytes instance
def is_bytes(string):
    """Check if a string is a bytes instance

    :param Union[str, bytes] string: A string that may be string or bytes like
    :return: Whether the provided string is a bytes type or not
    :rtype: bool
    """
    if six.PY3 and isinstance(string, (bytes, memoryview, bytearray)):  # noqa
        return True
    elif six.PY2 and isinstance(string, (buffer, bytearray)):  # noqa
        return True
    return False