<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def safe_str(obj):
 """ return the byte string representation of obj """

    try:
        return str(obj)
    except UnicodeEncodeError:
        # obj is unicode
        try:
            return unicode(obj).encode('unicode_escape')  # noqa for undefined-variable
        except NameError:
            # This is Python 3, just return the obj as it's already unicode
            return obj