javascript - 如何在 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 特定编码
推荐阅读
- javascript - 如何动态更新多个对象数组中的特定对象
- postgresql - 在两个 PostgreSQL 表之间创建关系
- regex - RegEx - 查找所有出现的单词并排除包含它的某些单词
- python - 基于每个唯一值条件的新熊猫布尔列
- javascript - Google 助理 API 使用情况
- javascript - 使滚动图标在 div 元素处停止,而不是使用 scrollTop
- sql-server-2008 - 从另一个表中插入数据 order by
- shell - Shell:非 ASCII 文本的 printf 对齐方式不一致
- android - DiffUtil 将错误的位置传递给 areContentsTheSame 方法
- python - 如何通过 cerberus 验证其字段可以是 dict 或 dict 列表的数据?