import six


def _compat_repr(repr_string, encoding='utf-8'):
    """
    Function to provide compatibility with Python 2 and 3 with the __repr__
    function. In Python 2, return a encoded version. In Python 3, return
    a unicode object. 
    """
    if six.PY2:
        return repr_string.encode(encoding)
    else:
        return repr_string