def safe_unicode(obj, *args):
    """ return the unicode representation of obj """
    try:
        return unicode(obj, *args)
    except UnicodeDecodeError:
        # obj is byte string
        ascii_text = str(obj).encode('string_escape')
        return unicode(ascii_text)
 return the unicode representation of obj 
recipes/Python/466341_Guaranteed_conversiunicode_or_byte/recipe-466341.py