需求:由于工作中需要检查一条消息中的敏感词,而日志里通常都是显示八进制,因此只看日志并不能看出是触发了哪个敏感词,需要写一个程序来自动显示触发了哪个敏感词。
s_hex = input() s_hex = s_hex[1:] s_hex = s_hex.split('\\') res = '' print(s_hex) for i in s_hex: tem = hex(int(i, 8)) tem = tem.replace('0', '\\') res += tem print("十六进制:", res) a = bytes(res, 'utf-8') b = a.decode('unicode_escape').encode('latin1').decode('utf-8') print("编码成汉字是:", b)
例如,输入\345\205\245\351\251\273
输出“入驻”