如何将十六进制+字符转换为 Python 中的字符
How to Convert hex+character to Character in Python
Str = """\x3Cstyle\x3E\x0A\x20\x20\x20.mainDiv\x0A\x20\x20\x7B\x0A\x20\x20width\x3A1000px\x3B\x0A\x20\x20background\x2Dimage\x3Aurl"""
我需要输出为:
<style\>
.mainDiv
{
width\:1000px;
background-image:URL
}
我需要使用 Python
对其进行解码
您必须将 'raw_unicode_escape'
与 'unicode_escape'
一起使用
Str = """\x3Cstyle\x3E\x0A\x20\x20\x20.mainDiv\x0A\x20\x20\x7B\x0A\x20\x20width\x3A1000px\x3B\x0A\x20\x20background\x2Dimage\x3Aurl"""
Str = Str.encode('raw_unicode_escape').decode('unicode_escape')
print(Str)
Python 文档:编解码器 Python Specific Encodings
Str = """\x3Cstyle\x3E\x0A\x20\x20\x20.mainDiv\x0A\x20\x20\x7B\x0A\x20\x20width\x3A1000px\x3B\x0A\x20\x20background\x2Dimage\x3Aurl"""
我需要输出为:
<style\>
.mainDiv
{
width\:1000px;
background-image:URL
}
我需要使用 Python
对其进行解码您必须将 'raw_unicode_escape'
与 'unicode_escape'
Str = """\x3Cstyle\x3E\x0A\x20\x20\x20.mainDiv\x0A\x20\x20\x7B\x0A\x20\x20width\x3A1000px\x3B\x0A\x20\x20background\x2Dimage\x3Aurl"""
Str = Str.encode('raw_unicode_escape').decode('unicode_escape')
print(Str)
Python 文档:编解码器 Python Specific Encodings