import string
printable = string.ascii_letters + string.digits + string.punctuation + ' '

def hex_escape(s):
    return ''.join(c if c in printable else '\\x{0:02x}'.format(ord(c)) for
        c in s)
Show non printable characters in a string