我正在尝试将字符串中的ASCII值转换为普通字符,但无论我怎么做,我都会得到像
这样的输出this\032is\032my\032\output\000
我需要
this is my output
感谢您的帮助!
答案 0 :(得分:1)
我用
解决了这个问题import re
def replace(match):
return chr(int(match.group(1)))
aux = str(element.text)
regex = re.compile(r"\\(\d{1,3})")
new = regex.sub(replace, aux)
其中element.text
是我需要转换的字符串
答案 1 :(得分:0)
\032
是十进制数26
的八进制数,因此它实际上不是空格字符,如果使用具有正确数字的十六进制值,则应该得到您想要的结果。 0x20 == 32
以下
>>> s = 'this\x20is\x20my\x20\output\00'
>>> print(s)
this is my \output