(obj, encoding='utf-8')
return obj.encode(encoding)
Makes sure the string is encoded as a byte string.

    :param obj: Python 2 string, Python 3 byte string, Unicode string to encode
    :param encoding: The encoding to use
    :return: The byte string that was encoded
Makes sure the string is encoded as a byte string.
Makes sure the string is encoded as a byte string .
def to_bytes(obj, encoding='utf-8'):
    """
    Makes sure the string is encoded as a byte string.

    :param obj: Python 2 string, Python 3 byte string, Unicode string to encode
    :param encoding: The encoding to use
    :return: The byte string that was encoded
    """
    if isinstance(obj, bytes):
        return obj

    return obj.encode(encoding)
def to_bytes ( obj , encoding = 'utf-8' ) : if isinstance ( obj , bytes ) : return obj return obj . encode ( encoding )