control_chars = ''.join(c for c in all_chars if unicodedata.category(c) == 'Cc'
    )
control_chars = ''.join(map(chr, list(range(0, 32)) + list(range(127, 160))))
control_char_re = re.compile('[%s]' % re.escape(control_chars))

def remove_control_chars(s):
    return control_char_re.sub('', s)
Stripping non printable characters from a string in python