(text, encoding=None, errors='strict')
return text.encode(encoding, errors)
Return the binary representation of ``text``. If ``text``
    is already a bytes object, return it as-is.
Return the binary representation of ``text``. If ``text``
    is already a bytes object, return it as-is.
Return the binary representation of text . If text is already a bytes object return it as - is .
def to_bytes(text, encoding=None, errors='strict'):
    """Return the binary representation of ``text``. If ``text``
    is already a bytes object, return it as-is."""
    if isinstance(text, bytes):
        return text
    if not isinstance(text, str):
        raise TypeError('to_bytes must receive a str or bytes '
                        f'object, got {type(text).__name__}')
    if encoding is None:
        encoding = 'utf-8'
    return text.encode(encoding, errors)
def to_bytes ( text , encoding = None , errors = 'strict' ) : if isinstance ( text , bytes ) : return text if not isinstance ( text , str ) : raise TypeError ( 'to_bytes must receive a str or bytes ' f'object, got {type(text).__name__}' ) if encoding is None : encoding = 'utf-8' return text . encode ( encoding , errors )