有些脚本文件中存在一些特殊的 ASCII控制字符,需要对这些字符进行处理
1 2 3 4 5 6 7 8 9 10 11 12
| import re
control_chars = ''.join(map(unichr,range(0, 32)+range(127,160))) control_char_re=re.compile('[%s]'%re.escape(control_chars))
def remove_control_chars(log, str): try: return control_char_re.sub('',str) except Exception: log.warn('remove control chars failed. {}',str)
|