<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_bytes(obj):
 """Ensures that the obj is of byte-type. """


    if PY3:
        if isinstance(obj, str):
            return obj.encode(settings.DEFAULT_ENCODING)
        else:
            return obj if isinstance(obj, bytes) else b''
    else:
        if isinstance(obj, str):
            return obj
        else:
            return obj.encode(settings.DEFAULT_ENCODING) if isinstance(obj, unicode) else ''